Class: Extant::AttributeDefinition
- Inherits:
-
Object
- Object
- Extant::AttributeDefinition
- Defined in:
- lib/extant/attribute_definition.rb
Instance Attribute Summary collapse
-
#allow_nil ⇒ Object
Returns the value of attribute allow_nil.
-
#coercer_class ⇒ Object
Returns the value of attribute coercer_class.
-
#default_value ⇒ Object
Returns the value of attribute default_value.
-
#has_default ⇒ Object
Returns the value of attribute has_default.
-
#name ⇒ Object
Returns the value of attribute name.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize(model, name, opts = {}) ⇒ AttributeDefinition
constructor
A new instance of AttributeDefinition.
Constructor Details
#initialize(model, name, opts = {}) ⇒ AttributeDefinition
Returns a new instance of AttributeDefinition.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/extant/attribute_definition.rb', line 6 def initialize(model, name, opts={}) self.name = name self.type = opts[:type] self.has_default = opts.key?(:default) self.default_value = opts[:default] self.allow_nil = opts.fetch(:allow_nil, true) if type self.coercer_class = Extant::Coercers.find(type) end model.instance_eval do define_method name do extant_attributes[name].value end define_method "#{name}=" do |val| extant_attributes[name].value = val end end end |
Instance Attribute Details
#allow_nil ⇒ Object
Returns the value of attribute allow_nil.
3 4 5 |
# File 'lib/extant/attribute_definition.rb', line 3 def allow_nil @allow_nil end |
#coercer_class ⇒ Object
Returns the value of attribute coercer_class.
3 4 5 |
# File 'lib/extant/attribute_definition.rb', line 3 def coercer_class @coercer_class end |
#default_value ⇒ Object
Returns the value of attribute default_value.
3 4 5 |
# File 'lib/extant/attribute_definition.rb', line 3 def default_value @default_value end |
#has_default ⇒ Object
Returns the value of attribute has_default.
3 4 5 |
# File 'lib/extant/attribute_definition.rb', line 3 def has_default @has_default end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/extant/attribute_definition.rb', line 3 def name @name end |
#type ⇒ Object
Returns the value of attribute type.
3 4 5 |
# File 'lib/extant/attribute_definition.rb', line 3 def type @type end |