Class: Simplifyapi::Property
- Inherits:
-
Object
- Object
- Simplifyapi::Property
- Defined in:
- lib/simplifyapi/property.rb
Instance Attribute Summary collapse
-
#getter ⇒ Object
readonly
Returns the value of attribute getter.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#setter ⇒ Object
readonly
Returns the value of attribute setter.
Instance Method Summary collapse
- #export(model) ⇒ Object
- #getter_defined? ⇒ Boolean
- #import(model, value) ⇒ Object
-
#initialize(name, &block) ⇒ Property
constructor
A new instance of Property.
- #setter_defined? ⇒ Boolean
Constructor Details
#initialize(name, &block) ⇒ Property
Returns a new instance of Property.
5 6 7 8 9 |
# File 'lib/simplifyapi/property.rb', line 5 def initialize name, &block @name = name instance_eval &block if block_given? end |
Instance Attribute Details
#getter ⇒ Object (readonly)
Returns the value of attribute getter.
3 4 5 |
# File 'lib/simplifyapi/property.rb', line 3 def getter @getter end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/simplifyapi/property.rb', line 3 def name @name end |
#setter ⇒ Object (readonly)
Returns the value of attribute setter.
3 4 5 |
# File 'lib/simplifyapi/property.rb', line 3 def setter @setter end |
Instance Method Details
#export(model) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/simplifyapi/property.rb', line 19 def export model if getter_defined? @getter.call model else model.send name end end |
#getter_defined? ⇒ Boolean
27 28 29 |
# File 'lib/simplifyapi/property.rb', line 27 def getter_defined? !!@getter end |
#import(model, value) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/simplifyapi/property.rb', line 11 def import model, value if setter_defined? @setter.call model, value else model.send "#{name}=", value end end |
#setter_defined? ⇒ Boolean
31 32 33 |
# File 'lib/simplifyapi/property.rb', line 31 def setter_defined? !!@setter end |