Module: Celluloid::FSM::ClassMethods

Defined in:
lib/vendor/celluloid/lib/celluloid/fsm.rb

Instance Method Summary collapse

Instance Method Details

#default_state(new_default = nil) ⇒ Object

Obtain or set the default state Passing a state name sets the default state



30
31
32
33
34
35
36
# File 'lib/vendor/celluloid/lib/celluloid/fsm.rb', line 30

def default_state(new_default = nil)
  if new_default
    @default_state = new_default.to_sym
  else
    defined?(@default_state) ? @default_state : DEFAULT_STATE
  end
end

#new(*args, &block) ⇒ Object

Ensure FSMs transition into the default state after they’re initialized



15
16
17
18
19
# File 'lib/vendor/celluloid/lib/celluloid/fsm.rb', line 15

def new(*args, &block)
  fsm = super
  fsm.transition default_state
  fsm
end

Ensure FSMs transition into the default state after they’re initialized



22
23
24
25
26
# File 'lib/vendor/celluloid/lib/celluloid/fsm.rb', line 22

def new_link(*args, &block)
  fsm = super
  fsm.transition default_state
  fsm
end

#state(*args, &block) ⇒ Object

Declare an FSM state and optionally provide a callback block to fire Options:

  • to: a state or array of states this state can transition to



46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/vendor/celluloid/lib/celluloid/fsm.rb', line 46

def state(*args, &block)
  if args.last.is_a? Hash
    options = args.pop.inject({}) { |h,(k,v)| h[k.to_s] = v; h }
  else
    options = {}
  end

  args.each do |name|
    name = name.to_sym
    states[name] = State.new(name, options['to'], &block)
  end
end

#statesObject

Obtain the valid states for this FSM



39
40
41
# File 'lib/vendor/celluloid/lib/celluloid/fsm.rb', line 39

def states
  @states ||= {}
end