Class: Virtus::Attribute::DefaultValue
- Inherits:
-
Object
- Object
- Virtus::Attribute::DefaultValue
- Defined in:
- lib/virtus/attribute/default_value.rb
Overview
Class representing the default value option
Constant Summary collapse
- SINGLETON_CLASSES =
[ ::NilClass, ::TrueClass, ::FalseClass, ::Numeric, ::Symbol ].freeze
Instance Attribute Summary collapse
-
#attribute ⇒ Virtus::Attribute::Object
readonly
private
Returns the attribute associated with this default value instance.
-
#value ⇒ Object
readonly
private
Returns the value instance.
Instance Method Summary collapse
-
#evaluate(instance) ⇒ Object
private
Evaluates the value.
-
#initialize(attribute, value) ⇒ undefined
constructor
private
Initializes an default value instance.
Constructor Details
#initialize(attribute, value) ⇒ undefined
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Initializes an default value instance
31 32 33 |
# File 'lib/virtus/attribute/default_value.rb', line 31 def initialize(attribute, value) @attribute, @value = attribute, value end |
Instance Attribute Details
#attribute ⇒ Virtus::Attribute::Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the attribute associated with this default value instance
14 15 16 |
# File 'lib/virtus/attribute/default_value.rb', line 14 def attribute @attribute end |
#value ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the value instance
21 22 23 |
# File 'lib/virtus/attribute/default_value.rb', line 21 def value @value end |
Instance Method Details
#evaluate(instance) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Evaluates the value
42 43 44 45 46 47 48 49 50 |
# File 'lib/virtus/attribute/default_value.rb', line 42 def evaluate(instance) if callable? call(instance) elsif cloneable? value.clone else value end end |