Class: Sphene::Attribute
- Inherits:
-
Object
- Object
- Sphene::Attribute
- Defined in:
- lib/sphene/attribute.rb
Instance Attribute Summary collapse
-
#default ⇒ Object
readonly
Returns the value of attribute default.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize(name, model, type: Types::Default, default: nil) ⇒ Attribute
constructor
A new instance of Attribute.
- #value ⇒ Object
- #value=(value) ⇒ Object
Constructor Details
Instance Attribute Details
#default ⇒ Object (readonly)
Returns the value of attribute default.
5 6 7 |
# File 'lib/sphene/attribute.rb', line 5 def default @default end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
5 6 7 |
# File 'lib/sphene/attribute.rb', line 5 def model @model end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/sphene/attribute.rb', line 5 def name @name end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
5 6 7 |
# File 'lib/sphene/attribute.rb', line 5 def type @type end |
Instance Method Details
#value ⇒ Object
14 15 16 17 18 |
# File 'lib/sphene/attribute.rb', line 14 def value return default_value unless ivar_defined?(:@value_before_cast) return @value if ivar_defined?(:@value) @value = type.cast(@value_before_cast) end |
#value=(value) ⇒ Object
20 21 22 23 |
# File 'lib/sphene/attribute.rb', line 20 def value=(value) remove_ivar(:@value) if ivar_defined?(:@value) @value_before_cast = value end |