Module: Statize::ClassMethods

Defined in:
lib/statize.rb

Overview

class methods start here

Instance Method Summary collapse

Instance Method Details

#event(evt, *args, &block) ⇒ Object

definition of event Using global parameter @profile during definition



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/statize.rb', line 47

def event(evt, *args, &block)
  
  evt = evt.to_sym
  add_event_block(@profile, evt, &block)

  args.first.each do |fromSt, toSt|
    fromSt = fromSt.to_sym
    toSt = toSt.to_sym
    add_state_events(@profile,fromSt, evt)
    add_state_transition(@profile, fromSt, toSt)
    add_event_states(@profile, evt, fromSt, toSt)
    add_profile_states(@profile, fromSt, toSt)
  end

end

#event_block_table(prof = :default) ⇒ Object



91
92
93
# File 'lib/statize.rb', line 91

def event_block_table(prof = :default)
  _event_block_table(prof).freeze
end

#event_states_table(prof = :default) ⇒ Object



87
88
89
# File 'lib/statize.rb', line 87

def event_states_table(prof = :default)
  _event_states_table(prof).freeze
end

#initial_state(prof = :default) ⇒ Object



75
76
77
# File 'lib/statize.rb', line 75

def initial_state(prof = :default)
  @ops[prof][:initial_state].to_s.freeze
end

#meaning_states_table(prof = :default) ⇒ Object



103
104
105
# File 'lib/statize.rb', line 103

def meaning_states_table(prof = :default)
  _meaning_states_table(prof).freeze
end

#profile_states_list(prof = :default) ⇒ Object



95
96
97
# File 'lib/statize.rb', line 95

def profile_states_list(prof = :default)
  _profile_states_list(prof).freeze
end

#state_attr_name(prof = :default) ⇒ Object



71
72
73
# File 'lib/statize.rb', line 71

def state_attr_name(prof = :default)
  @ops[prof][:state_attr_name].to_s.freeze
end

#state_events_table(prof = :default) ⇒ Object



83
84
85
# File 'lib/statize.rb', line 83

def state_events_table(prof = :default)
  _state_events_table(prof).freeze
end

#state_meaning(ops) ⇒ Object

Raises:



63
64
65
66
67
68
69
# File 'lib/statize.rb', line 63

def state_meaning(ops)
  raise Error, "Hash expected" if not ops.is_a?(Hash) 
  ops.each do |k,v|
    add_state_meaning(@profile, k, v)
    add_meaning_states(@profile, v, k)
  end
end

#state_meaning_table(prof = :default) ⇒ Object



99
100
101
# File 'lib/statize.rb', line 99

def state_meaning_table(prof = :default)
  _state_meaning_table(prof).freeze
end

#state_profilesObject



107
108
109
# File 'lib/statize.rb', line 107

def state_profiles
  @ops.keys.freeze
end

#stateful(opts = { }, &block) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/statize.rb', line 23

def stateful(opts = {  }, &block)
  @ops = {  } if @ops.nil?
  ops = {
    initial_state: :open,
    state_attr_name: "state",
  } 

  @profile = opts[:profile] || :default 

  #opts.delete(:profile)

  ops.merge!(opts) if not opts.nil? and opts.is_a?(Hash)

  @ops[@profile] = {  }
  @ops[@profile].merge!(ops)

  if block
    class_eval(&block)
  end

end

#states_table(prof = :default) ⇒ Object



79
80
81
# File 'lib/statize.rb', line 79

def states_table(prof = :default)
  _states_transfer_table(prof).freeze
end