Class: Superstore::AttributeMethods::Definition

Inherits:
Object
  • Object
show all
Defined in:
lib/superstore/attribute_methods/definition.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model, name, type_class, options) ⇒ Definition

Returns a new instance of Definition.



5
6
7
8
# File 'lib/superstore/attribute_methods/definition.rb', line 5

def initialize(model, name, type_class, options)
  @name = name.to_s
  @type = type_class.new(model, options)
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/superstore/attribute_methods/definition.rb', line 4

def name
  @name
end

#typeObject (readonly)

Returns the value of attribute type.



4
5
6
# File 'lib/superstore/attribute_methods/definition.rb', line 4

def type
  @type
end

Instance Method Details

#instantiate(value) ⇒ Object



10
11
12
13
14
# File 'lib/superstore/attribute_methods/definition.rb', line 10

def instantiate(value)
  return if value.nil?

  value.kind_of?(String) ? type.decode(value) : type.typecast(value)
end