Class: Progressive::Specification::State
- Inherits:
-
Object
- Object
- Progressive::Specification::State
- Defined in:
- lib/progressive/specification.rb
Instance Attribute Summary collapse
-
#events ⇒ Object
readonly
Returns the value of attribute events.
Instance Method Summary collapse
-
#event(*args) ⇒ Object
Public: Defines events.
-
#event?(state) ⇒ Boolean
Public: Determine if a given event exists.
-
#initialize(&block) ⇒ State
constructor
A new instance of State.
Constructor Details
#initialize(&block) ⇒ State
Returns a new instance of State.
6 7 8 9 10 |
# File 'lib/progressive/specification.rb', line 6 def initialize(&block) @events = {} return unless block.present? instance_eval(&block) end |
Instance Attribute Details
#events ⇒ Object (readonly)
Returns the value of attribute events.
4 5 6 |
# File 'lib/progressive/specification.rb', line 4 def events @events end |
Instance Method Details
#event(*args) ⇒ Object
Public: Defines events
args - Can either be symbol (:potential) or hash (:archive => :archived)
Returns Progression::Specification::Event
17 18 19 20 |
# File 'lib/progressive/specification.rb', line 17 def event(*args) name, to = args.first.is_a?(Symbol) ? args.first : args.first.to_a.flatten @events[name.to_sym] = Event.new(name, to) end |
#event?(state) ⇒ Boolean
Public: Determine if a given event exists.
state - Event name to check for.
Returns true if event exists, false if not.
27 28 29 |
# File 'lib/progressive/specification.rb', line 27 def event?(state) @events.key?(state.to_sym) end |