Class: StateFu::Sprocket
- Includes:
- HasOptions, Applicable
- Defined in:
- lib/sprocket.rb
Overview
the abstract superclass of State & Event defines behaviours shared by both classes
Instance Attribute Summary collapse
-
#hooks ⇒ Object
readonly
Returns the value of attribute hooks.
-
#machine ⇒ Object
readonly
Returns the value of attribute machine.
-
#name ⇒ Object
(also: #to_sym)
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#==(other) ⇒ Object
allows state == <name> || event == <name> to return true.
-
#===(other) ⇒ Object
allows case equality tests against the state/event’s name eg case state when :new …
- #add_hook(slot, name, value) ⇒ Object
- #deep_copy ⇒ Object
-
#initialize(machine, name, options = {}) ⇒ Sprocket
constructor
A new instance of Sprocket.
-
#lathe(options = {}, &block) ⇒ Object
yields a lathe for self; useful for updating machine definitions on the fly.
- #serializable? ⇒ Boolean
- #to_s ⇒ Object
Methods included from HasOptions
Methods included from Applicable
Constructor Details
Instance Attribute Details
#hooks ⇒ Object (readonly)
Returns the value of attribute hooks.
8 9 10 |
# File 'lib/sprocket.rb', line 8 def hooks @hooks end |
#machine ⇒ Object (readonly)
Returns the value of attribute machine.
8 9 10 |
# File 'lib/sprocket.rb', line 8 def machine @machine end |
#name ⇒ Object (readonly) Also known as: to_sym
Returns the value of attribute name.
8 9 10 |
# File 'lib/sprocket.rb', line 8 def name @name end |
Instance Method Details
#==(other) ⇒ Object
allows state == <name> || event == <name> to return true
38 39 40 41 42 43 44 |
# File 'lib/sprocket.rb', line 38 def == other if other.is_a?(Symbol) self.name == other else super other end end |
#===(other) ⇒ Object
allows case equality tests against the state/event’s name eg case state when :new
...
end
52 53 54 |
# File 'lib/sprocket.rb', line 52 def === other self.to_sym === other.to_sym || super(other) end |
#add_hook(slot, name, value) ⇒ Object
20 21 22 |
# File 'lib/sprocket.rb', line 20 def add_hook slot, name, value @hooks[slot.to_sym] << [name.to_sym, value] end |
#deep_copy ⇒ Object
29 30 31 |
# File 'lib/sprocket.rb', line 29 def deep_copy raise NotImeplementedError # abstract end |
#lathe(options = {}, &block) ⇒ Object
yields a lathe for self; useful for updating machine definitions on the fly
25 26 27 |
# File 'lib/sprocket.rb', line 25 def lathe(={}, &block) StateFu::Lathe.new( machine, self, , &block ) end |
#serializable? ⇒ Boolean
56 57 58 |
# File 'lib/sprocket.rb', line 56 def serializable? !hooks.values.flatten.map(&:class).include?(Proc) && !!(.to_yaml rescue false) end |
#to_s ⇒ Object
33 34 35 |
# File 'lib/sprocket.rb', line 33 def to_s "#<#{self.class}::#{self.object_id} @name=#{name.inspect}>" end |