Class: Holotype::Attribute
- Inherits:
-
Object
- Object
- Holotype::Attribute
- Defined in:
- lib/holotype/attribute.rb,
lib/holotype/attribute/definition.rb,
lib/holotype/attribute/read_only_error.rb,
lib/holotype/attribute/immutable_value_error.rb,
lib/holotype/attribute/frozen_modification_error.rb,
lib/holotype/attribute/definition/no_value_class_error.rb,
lib/holotype/attribute/definition/default_conflict_error.rb,
lib/holotype/attribute/definition/required_conflict_error.rb,
lib/holotype/attribute/definition/no_collection_class_error.rb
Defined Under Namespace
Classes: Definition, FrozenModificationError, ImmutableValueError, ReadOnlyError
Instance Attribute Summary collapse
-
#definition ⇒ Object
readonly
Returns the value of attribute definition.
-
#owner ⇒ Object
readonly
Returns the value of attribute owner.
Instance Method Summary collapse
-
#initialize(owner, definition, **options) ⇒ Attribute
constructor
A new instance of Attribute.
- #name ⇒ Object
- #value ⇒ Object
- #value=(new_value) ⇒ Object
Constructor Details
#initialize(owner, definition, **options) ⇒ Attribute
Returns a new instance of Attribute.
12 13 14 15 16 17 |
# File 'lib/holotype/attribute.rb', line 12 def initialize owner, definition, ** @definition = definition @owner = owner set_value [:value] if .key? :value end |
Instance Attribute Details
#definition ⇒ Object (readonly)
Returns the value of attribute definition.
10 11 12 |
# File 'lib/holotype/attribute.rb', line 10 def definition @definition end |
#owner ⇒ Object (readonly)
Returns the value of attribute owner.
10 11 12 |
# File 'lib/holotype/attribute.rb', line 10 def owner @owner end |
Instance Method Details
#name ⇒ Object
19 20 21 |
# File 'lib/holotype/attribute.rb', line 19 def name definition.name end |
#value ⇒ Object
23 24 25 26 |
# File 'lib/holotype/attribute.rb', line 23 def value set_value definition.default owner unless @has_value @value end |
#value=(new_value) ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/holotype/attribute.rb', line 28 def value= new_value raise ImmutableValueError.new name if definition.immutable? raise FrozenModificationError.new name if owner.frozen? raise ReadOnlyError.new name if definition.read_only? set_value new_value end |