Class: Progressive::Specification::State

Inherits:
Object
  • Object
show all
Defined in:
lib/progressive/specification.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#eventsObject (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.

Returns:

  • (Boolean)


27
28
29
# File 'lib/progressive/specification.rb', line 27

def event?(state)
  @events.key?(state.to_sym)
end