class Calibrate::Configurable::FieldMetadata
Constants
- DEFAULT_PROPERTIES
Attributes
default_value[RW]
name[RW]
Public Class Methods
new(name, value)
click to toggle source
# File lib/calibrate/configurable/field-metadata.rb, line 13 def initialize(name, value) @name = name @default_value = value @properties = DEFAULT_PROPERTIES.clone end
Public Instance Methods
build_default_value()
click to toggle source
# File lib/calibrate/configurable/field-metadata.rb, line 80 def build_default_value if Module === @default_value and Configurable > @default_value value = @default_value.new value.class.set_defaults_on(value) value else copy_value(@default_value) end end
copy_from(instance)
click to toggle source
# File lib/calibrate/configurable/field-metadata.rb, line 75 def copy_from(instance) return if unset_on?(instance) copy_value(immediate_value_on(instance)) end
copy_value(value)
click to toggle source
# File lib/calibrate/configurable/field-metadata.rb, line 90 def copy_value(value) case value when Symbol, Numeric, NilClass, TrueClass, FalseClass value else if value.class == BasicObject value elsif value.respond_to?(:dup) value.dup elsif value.respond_to?(:clone) value.clone else value end end end
immediate_value_on(instance)
click to toggle source
# File lib/calibrate/configurable/field-metadata.rb, line 107 def immediate_value_on(instance) instance.instance_variable_get(ivar_name) #instance.__send__(reader_method) end
inspect()
click to toggle source
# File lib/calibrate/configurable/field-metadata.rb, line 19 def inspect set_props = DEFAULT_PROPERTIES.keys.find_all do |prop| @properties[prop] end "Field: #{name}: #{default_value.inspect} #{set_props.inspect}" end
inspect_on(instance, indent=nil)
click to toggle source
# File lib/calibrate/configurable/field-metadata.rb, line 26 def inspect_on(instance, indent=nil) set_props = DEFAULT_PROPERTIES.keys.find_all do |prop| @properties[prop] end "Field: #{name}: #{value_on(instance).inspect} \n#{indent||""}(default: #{default_value.inspect} immediate: #{immediate_value_on(instance).inspect}) #{set_props.inspect}" end
is(property)
click to toggle source
# File lib/calibrate/configurable/field-metadata.rb, line 50 def is(property) validate_property_name(property) @properties[property] = true self end
is?(property)
click to toggle source
# File lib/calibrate/configurable/field-metadata.rb, line 39 def is?(property) validate_property_name(property) @properties[property] end
is_not(property)
click to toggle source
# File lib/calibrate/configurable/field-metadata.rb, line 56 def is_not(property) validate_property_name(property) @properties[property] = false self end
Also aliased as: isnt
is_not?(property)
click to toggle source
# File lib/calibrate/configurable/field-metadata.rb, line 44 def is_not?(property) validate_property_name(property) !@properties[property] end
Also aliased as: isnt?
ivar_name()
click to toggle source
# File lib/calibrate/configurable/field-metadata.rb, line 63 def ivar_name "@#{name}" end
missing_on?(instance)
click to toggle source
# File lib/calibrate/configurable/field-metadata.rb, line 136 def missing_on?(instance) return false unless is?(:required) if instance.respond_to?(:runtime?) and !instance.runtime? return runtime_missing_on?(instance) else return !set_on?(instance) end end
reader_method()
click to toggle source
# File lib/calibrate/configurable/field-metadata.rb, line 71 def reader_method name end
runtime_missing_on?(instance)
click to toggle source
# File lib/calibrate/configurable/field-metadata.rb, line 145 def runtime_missing_on?(instance) return false if is?(:runtime) return true unless instance.instance_variable_defined?(ivar_name) value = immediate_value_on(instance) if ProxyValue === value value.field.runtime_missing_on?(value.source) else false end end
set_on?(instance)
click to toggle source
# File lib/calibrate/configurable/field-metadata.rb, line 121 def set_on?(instance) return true unless instance.__send__(reader_method).nil? return false unless instance.instance_variable_defined?(ivar_name) value = immediate_value_on(instance) if ProxyValue === value value.field.set_on?(value.source) else true end end
unset_on?(instance)
click to toggle source
# File lib/calibrate/configurable/field-metadata.rb, line 132 def unset_on?(instance) !set_on?(instance) end
validate_property_name(name)
click to toggle source
# File lib/calibrate/configurable/field-metadata.rb, line 33 def validate_property_name(name) unless DEFAULT_PROPERTIES.has_key?(name) raise "Invalid field property #{name.inspect} - valid are: #{DEFAULT_PROPERTIES.keys.inspect}" end end
value_on(instance)
click to toggle source
# File lib/calibrate/configurable/field-metadata.rb, line 112 def value_on(instance) value = immediate_value_on(instance) if ProxyValue === value value.field.value_on(value.source) else value end end
writer_method()
click to toggle source
# File lib/calibrate/configurable/field-metadata.rb, line 67 def writer_method "#{name}=" end