Class: ActiveEntity::Attribute
- Inherits:
-
Object
- Object
- ActiveEntity::Attribute
- Defined in:
- lib/active_entity/attribute.rb
Overview
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#cast!(value) ⇒ Object
Casted value.
- #cast_by ⇒ Proc
-
#initialize(name, options = {}) ⇒ Attribute
constructor
A new instance of Attribute.
- #type ⇒ Class, ...
Constructor Details
#initialize(name, options = {}) ⇒ Attribute
Returns a new instance of Attribute.
28 29 30 31 |
# File 'lib/active_entity/attribute.rb', line 28 def initialize(name, = {}) raise ArgumentError unless .is_a?(Hash) @name, @options = name, end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
24 25 26 |
# File 'lib/active_entity/attribute.rb', line 24 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
24 25 26 |
# File 'lib/active_entity/attribute.rb', line 24 def @options end |
Instance Method Details
#cast!(value) ⇒ Object
Returns casted value.
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/active_entity/attribute.rb', line 46 def cast!(value) case when type cast_by_defined_type(value) when cast_by cast_by.call(value) else value end end |
#cast_by ⇒ Proc
39 40 41 |
# File 'lib/active_entity/attribute.rb', line 39 def cast_by @options[:cast_by] end |
#type ⇒ Class, ...
34 35 36 |
# File 'lib/active_entity/attribute.rb', line 34 def type @options[:type] end |