Class: YADM::Mapping::Attribute
- Inherits:
-
Object
- Object
- YADM::Mapping::Attribute
- Defined in:
- lib/yadm/mapping/attribute.rb
Constant Summary collapse
- COERCIONS =
{ Integer => -> (value) { value.to_i }, String => -> (value) { value.to_s } }.tap do |hash| hash.default = -> (value) { value } end
Instance Method Summary collapse
- #==(other) ⇒ Object
- #coerce(value) ⇒ Object
-
#initialize(type) ⇒ Attribute
constructor
A new instance of Attribute.
Constructor Details
#initialize(type) ⇒ Attribute
Returns a new instance of Attribute.
14 15 16 |
# File 'lib/yadm/mapping/attribute.rb', line 14 def initialize(type) @type = type end |
Instance Method Details
#==(other) ⇒ Object
18 19 20 |
# File 'lib/yadm/mapping/attribute.rb', line 18 def ==(other) type == other.type end |
#coerce(value) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/yadm/mapping/attribute.rb', line 22 def coerce(value) if value.nil? nil else COERCIONS[type].call(value) end end |