Class: SimpleObjectSerialization::Attribute
- Inherits:
-
Object
- Object
- SimpleObjectSerialization::Attribute
- Defined in:
- lib/simple_object_serialization/attribute.rb
Instance Attribute Summary collapse
-
#block ⇒ Object
readonly
Returns the value of attribute block.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#initialize(name, options, block) ⇒ Attribute
constructor
A new instance of Attribute.
- #skip_for?(serializer) ⇒ Boolean
- #value_for(serializer) ⇒ Object
Constructor Details
#initialize(name, options, block) ⇒ Attribute
Returns a new instance of Attribute.
7 8 9 10 11 |
# File 'lib/simple_object_serialization/attribute.rb', line 7 def initialize(name, , block) @name = name = @block = block end |
Instance Attribute Details
#block ⇒ Object (readonly)
Returns the value of attribute block.
5 6 7 |
# File 'lib/simple_object_serialization/attribute.rb', line 5 def block @block end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/simple_object_serialization/attribute.rb', line 5 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
5 6 7 |
# File 'lib/simple_object_serialization/attribute.rb', line 5 def end |
Instance Method Details
#skip_for?(serializer) ⇒ Boolean
13 14 15 |
# File 'lib/simple_object_serialization/attribute.rb', line 13 def skip_for?(serializer) [:if] ? !serializer.instance_eval(&[:if]) : false end |
#value_for(serializer) ⇒ Object
17 18 19 |
# File 'lib/simple_object_serialization/attribute.rb', line 17 def value_for(serializer) block ? serializer.instance_eval(&block) : serializer.object.public_send(name) end |