Method: Extant::AttributeDefinition#initialize
- Defined in:
- lib/extant/attribute_definition.rb
#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 |