Module: Mugatu::AttributeType
Instance Method Summary collapse
- #cast(value) ⇒ Object
- #get_cast_with ⇒ Object
- #raise_cast_error(value) ⇒ Object
- #set_cast_with(sym) ⇒ Object
Instance Method Details
#cast(value) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/mugatu/attribute_type.rb', line 11 def cast(value) if value.respond_to?(get_cast_with) value.send(get_cast_with) else raise_cast_error(value) end end |
#get_cast_with ⇒ Object
7 8 9 |
# File 'lib/mugatu/attribute_type.rb', line 7 def get_cast_with @cast_with end |
#raise_cast_error(value) ⇒ Object
19 20 21 |
# File 'lib/mugatu/attribute_type.rb', line 19 def raise_cast_error(value) raise TypeError, "cannot cast #{value} into #{name} (TypeError)" end |
#set_cast_with(sym) ⇒ Object
3 4 5 |
# File 'lib/mugatu/attribute_type.rb', line 3 def set_cast_with(sym) @cast_with = sym end |