Class: StateStep::StateProfile

Inherits:
Object
  • Object
show all
Includes:
TR::CondUtils
Defined in:
lib/state_step/state_profile.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#default_stateObject (readonly)

Returns the value of attribute default_state.



12
13
14
# File 'lib/state_step/state_profile.rb', line 12

def default_state
  @default_state
end

#state_attrObject (readonly)

Returns the value of attribute state_attr.



12
13
14
# File 'lib/state_step/state_profile.rb', line 12

def state_attr
  @state_attr
end

Instance Method Details

#default(st) ⇒ Object Also known as: default_status

DSL



19
20
21
# File 'lib/state_step/state_profile.rb', line 19

def default(st)
  @default_state = st
end

#defined_statesObject



80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/state_step/state_profile.rb', line 80

def defined_states
  
  if @_allStates.nil?
    @_allStates = []
    states.each do |k,v|
      @_allStates << k.to_s
      v.each do |vk, vv|
        @_allStates << vk.to_s
      end
    end
    @_allStates = @_allStates.uniq
  end
  @_allStates
end

#next_actionsObject

DSL



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/state_step/state_profile.rb', line 62

def next_actions
  if @next_actions.nil?
    @next_actions = { }

    states.each do |from, tos|
      next_actions[from] = [] if next_actions[from].nil?

      tos.each do |to, val|
        next_actions[from] << val.action_name
      end

    end

  end

  @next_actions
end

#parse_init(&block) ⇒ Object



14
15
16
# File 'lib/state_step/state_profile.rb', line 14

def parse_init(&block)
  self.instance_eval(&block)
end

#state(st, &block) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/state_step/state_profile.rb', line 29

def state(st, &block)
  trans = st[:trans]
  raise IncompleteStateSpec, "State transfer 'from' => 'to' state is not given" if is_empty?(trans)

  from = trans.keys.first
  to = trans.values.first
  act = st[:action]

  str = StateTrans.new(from, to, act, &block)

  states[from] = {} if states[from].nil?
  states[from][to] = str

  next_states[from] = [] if next_states[from].nil?
  next_states[from] << to

  actions[act] = str

  st
end

#state_field(field) ⇒ Object Also known as: status_field



24
25
26
# File 'lib/state_step/state_profile.rb', line 24

def state_field(field)
  @state_attr = field
end

#trigger_action(act) ⇒ Object



50
51
52
53
54
55
56
57
58
# File 'lib/state_step/state_profile.rb', line 50

def trigger_action(act)
  if actions.keys.include?(act) 
    actions[act].trigger

  else
    raise ActionNotDefined, "Active '#{act}' to trigger not defined"

  end
end