Class: AttributeDefaults::Default
- Inherits:
-
Object
- Object
- AttributeDefaults::Default
- Defined in:
- lib/attribute_defaults/default.rb
Instance Attribute Summary collapse
-
#attribute ⇒ Object
readonly
Returns the value of attribute attribute.
Instance Method Summary collapse
-
#initialize(attribute, value) ⇒ Default
constructor
A new instance of Default.
- #value(record) ⇒ Object
Constructor Details
#initialize(attribute, value) ⇒ Default
Returns a new instance of Default.
5 6 7 |
# File 'lib/attribute_defaults/default.rb', line 5 def initialize(attribute, value) @attribute, @value = attribute.to_s, value end |
Instance Attribute Details
#attribute ⇒ Object (readonly)
Returns the value of attribute attribute.
3 4 5 |
# File 'lib/attribute_defaults/default.rb', line 3 def attribute @attribute end |
Instance Method Details
#value(record) ⇒ Object
9 10 11 12 13 14 15 16 17 |
# File 'lib/attribute_defaults/default.rb', line 9 def value(record) if @value.is_a?(Symbol) record.send(@value) elsif @value.respond_to?(:call) @value.call(record) else @value.duplicable? ? @value.dup : @value end end |