Class: SolidObjects::StateDefinition
- Inherits:
-
Object
- Object
- SolidObjects::StateDefinition
- Defined in:
- lib/solid_objects/state.rb,
sig/generated/lib/solid_objects/state.rbs
Defined Under Namespace
Classes: Attribute
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
Instance Method Summary collapse
- #attribute(name, default: nil) ⇒ Attribute
- #duplicate ⇒ StateDefinition
-
#initialize ⇒ StateDefinition
constructor
A new instance of StateDefinition.
- #to_h ⇒ Hash[Symbol, Attribute]
Constructor Details
#initialize ⇒ StateDefinition
Returns a new instance of StateDefinition.
10 11 12 |
# File 'lib/solid_objects/state.rb', line 10 def initialize @attributes = {} end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
36 37 38 |
# File 'lib/solid_objects/state.rb', line 36 def attributes @attributes end |
Instance Method Details
#attribute(name, default: nil) ⇒ Attribute
15 16 17 18 19 20 |
# File 'lib/solid_objects/state.rb', line 15 def attribute(name, default: nil) attribute_name = name.to_sym raise InvalidActor, "state attribute #{attribute_name.inspect} is already defined" if attributes.key?(attribute_name) attributes[attribute_name] = Attribute.new(name: attribute_name, default:) end |
#duplicate ⇒ StateDefinition
28 29 30 31 32 |
# File 'lib/solid_objects/state.rb', line 28 def duplicate self.class.new.tap do |definition| attributes.each_value { |attribute| definition.attribute(attribute.name, default: attribute.default) } end end |
#to_h ⇒ Hash[Symbol, Attribute]
23 24 25 |
# File 'lib/solid_objects/state.rb', line 23 def to_h attributes.dup.freeze end |