Module: StateStep
- Includes:
- TR::CondUtils
- Defined in:
- lib/state_step.rb,
lib/state_step/version.rb,
lib/state_step/state_trans.rb,
lib/state_step/state_profile.rb
Defined Under Namespace
Modules: ClassMethods
Classes: ActionNotDefined, Error, IncompleteStateSpec, StateProfile, StateTrans
Constant Summary
collapse
- VERSION =
"0.1.1"
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.included(klass) ⇒ Object
60
61
62
|
# File 'lib/state_step.rb', line 60
def self.included(klass)
klass.extend(ClassMethods)
end
|
.logger(tag = nil, &block) ⇒ Object
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/state_step.rb', line 15
def self.logger(tag = nil, &block)
if @_logger.nil?
@_logger = TeLogger::Tlogger.new
end
if block
if not_empty?(tag)
@_logger.with_tag(tag, &block)
else
@_logger.with_tag(@_logger.tag, &block)
end
else
if is_empty?(tag)
@_logger.tag = :state_step
@_logger
else
@_logger.tag = tag
@_logger
end
end
end
|
Instance Method Details
#default_status ⇒ Object
68
69
70
|
# File 'lib/state_step.rb', line 68
def default_status
self.class.profile.default_state
end
|
#init_default_status ⇒ Object
72
73
74
75
76
77
78
79
80
81
82
|
# File 'lib/state_step.rb', line 72
def init_default_status
if status_field_exist?
self.send("#{state_field_name}=", default_status)
else
StateStep.logger.debug "Status field '#{state_field_name}' does not exist on #{self}"
raise Error, "Status field '#{state_field_name}' does not exist on '#{self}'"
end
end
|
#is_current_status?(st) ⇒ Boolean
Also known as:
is_current_state?
84
85
86
87
88
89
90
|
# File 'lib/state_step.rb', line 84
def is_current_status?(st)
if status_field_exist?
self.send("#{state_field_name}") == st.to_s
else
raise Error, "Status field name '#{state_field_name}' not defined"
end
end
|
#next_actions ⇒ Object
120
121
122
123
124
125
126
|
# File 'lib/state_step.rb', line 120
def next_actions
currAction = self.send("#{state_field_name}")
currAction = currAction.to_sym if not_empty?(currAction)
res = self.class.profile.next_actions[currAction] || []
res
end
|
#state_field_name ⇒ Object
93
94
95
|
# File 'lib/state_step.rb', line 93
def state_field_name
self.class.profile.state_attr
end
|
#state_trigger_action(action, raise_if_not_found = false) ⇒ Object
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
# File 'lib/state_step.rb', line 97
def state_trigger_action(action, raise_if_not_found = false)
if status_field_exist?
begin
nst = self.class.profile.trigger_action(action)
self.send("#{self.class.profile.state_attr}=", nst)
true
rescue ActionNotDefined => e
if raise_if_not_found == true
raise e
else
false
end
end
else
StateStep.logger.debug "Status field '#{state_field_name}' does not exist"
end
end
|