workflow 2.0.2 → 3.1.0.pre

Sign up to get free protection for your applications and to get access to all the features.
data/lib/workflow.rb CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
 
3
3
  require 'workflow/specification'
4
4
 
5
- # See also README.markdown for documentation
5
+ # See also README for documentation
6
6
  module Workflow
7
7
  module ClassMethods
8
8
  attr_reader :workflow_spec
@@ -61,12 +61,12 @@ module Workflow
61
61
  state.events.flat.each do |event|
62
62
  event_name = event.name
63
63
  module_eval do
64
- define_method "#{event_name}!".to_sym do |*args|
65
- process_event!(event_name, *args)
64
+ define_method "#{event_name}!".to_sym do |*args, **kwargs|
65
+ process_event!(event_name, *args, **kwargs)
66
66
  end
67
67
 
68
- define_method "can_#{event_name}?" do
69
- return !!current_state.events.first_applicable(event_name, self)
68
+ define_method "can_#{event_name}?".to_sym do |*args, **kwargs|
69
+ return !!current_state.events.first_applicable(event_name, self, args)
70
70
  end
71
71
  end
72
72
  end
@@ -94,8 +94,8 @@ module Workflow
94
94
  @halted_because
95
95
  end
96
96
 
97
- def process_event!(name, *args)
98
- event = current_state.events.first_applicable(name, self)
97
+ def process_event!(name, *args, **kwargs)
98
+ event = current_state.events.first_applicable(name, self, args)
99
99
  raise NoTransitionAllowed.new(
100
100
  "There is no event #{name.to_sym} defined for the #{current_state} state") \
101
101
  if event.nil?
@@ -107,26 +107,26 @@ module Workflow
107
107
  from = current_state
108
108
  to = spec.states[event.transitions_to]
109
109
 
110
- run_before_transition(from, to, name, *args)
110
+ run_before_transition(from, to, name, *args, **kwargs)
111
111
  return false if @halted
112
112
 
113
113
  begin
114
- return_value = run_action(event.action, *args) || run_action_callback(event.name, *args)
114
+ return_value = run_action(event.action, *args, **kwargs) || run_action_callback(event.name, *args, **kwargs)
115
115
  rescue StandardError => e
116
- run_on_error(e, from, to, name, *args)
116
+ run_on_error(e, from, to, name, *args, **kwargs)
117
117
  end
118
118
 
119
119
  return false if @halted
120
120
 
121
- run_on_transition(from, to, name, *args)
121
+ run_on_transition(from, to, name, *args, **kwargs)
122
122
 
123
- run_on_exit(from, to, name, *args)
123
+ run_on_exit(from, to, name, *args, **kwargs)
124
124
 
125
125
  transition_value = persist_workflow_state to.to_s
126
126
 
127
- run_on_entry(to, from, name, *args)
127
+ run_on_entry(to, from, name, *args, **kwargs)
128
128
 
129
- run_after_transition(from, to, name, *args)
129
+ run_after_transition(from, to, name, *args, **kwargs)
130
130
 
131
131
  return_value.nil? ? transition_value : return_value
132
132
  end
@@ -169,31 +169,31 @@ module Workflow
169
169
  end
170
170
  end
171
171
 
172
- def run_before_transition(from, to, event, *args)
173
- instance_exec(from.name, to.name, event, *args, &spec.before_transition_proc) if
172
+ def run_before_transition(from, to, event, *args, **kwargs)
173
+ instance_exec(from.name, to.name, event, *args, **kwargs, &spec.before_transition_proc) if
174
174
  spec.before_transition_proc
175
175
  end
176
176
 
177
- def run_on_error(error, from, to, event, *args)
177
+ def run_on_error(error, from, to, event, *args, **kwargs)
178
178
  if spec.on_error_proc
179
- instance_exec(error, from.name, to.name, event, *args, &spec.on_error_proc)
179
+ instance_exec(error, from.name, to.name, event, *args, **kwargs, &spec.on_error_proc)
180
180
  halt(error.message)
181
181
  else
182
182
  raise error
183
183
  end
184
184
  end
185
185
 
186
- def run_on_transition(from, to, event, *args)
187
- instance_exec(from.name, to.name, event, *args, &spec.on_transition_proc) if spec.on_transition_proc
186
+ def run_on_transition(from, to, event, *args, **kwargs)
187
+ instance_exec(from.name, to.name, event, *args, **kwargs, &spec.on_transition_proc) if spec.on_transition_proc
188
188
  end
189
189
 
190
- def run_after_transition(from, to, event, *args)
191
- instance_exec(from.name, to.name, event, *args, &spec.after_transition_proc) if
190
+ def run_after_transition(from, to, event, *args, **kwargs)
191
+ instance_exec(from.name, to.name, event, *args, **kwargs, &spec.after_transition_proc) if
192
192
  spec.after_transition_proc
193
193
  end
194
194
 
195
- def run_action(action, *args)
196
- instance_exec(*args, &action) if action
195
+ def run_action(action, *args, **kwargs)
196
+ instance_exec(*args, **kwargs, &action) if action
197
197
  end
198
198
 
199
199
  def has_callback?(action)
@@ -206,27 +206,27 @@ module Workflow
206
206
  self.private_methods(false).map(&:to_sym).include?(action)
207
207
  end
208
208
 
209
- def run_action_callback(action_name, *args)
209
+ def run_action_callback(action_name, *args, **kwargs)
210
210
  action = action_name.to_sym
211
- self.send(action, *args) if has_callback?(action)
211
+ self.send(action, *args, **kwargs) if has_callback?(action)
212
212
  end
213
213
 
214
- def run_on_entry(state, prior_state, triggering_event, *args)
214
+ def run_on_entry(state, prior_state, triggering_event, *args, **kwargs)
215
215
  if state.on_entry
216
- instance_exec(prior_state.name, triggering_event, *args, &state.on_entry)
216
+ instance_exec(prior_state.name, triggering_event, *args, **kwargs, &state.on_entry)
217
217
  else
218
218
  hook_name = "on_#{state}_entry"
219
- self.send hook_name, prior_state, triggering_event, *args if has_callback?(hook_name)
219
+ self.send hook_name, prior_state, triggering_event, *args, **kwargs if has_callback?(hook_name)
220
220
  end
221
221
  end
222
222
 
223
- def run_on_exit(state, new_state, triggering_event, *args)
223
+ def run_on_exit(state, new_state, triggering_event, *args, **kwargs)
224
224
  if state
225
225
  if state.on_exit
226
- instance_exec(new_state.name, triggering_event, *args, &state.on_exit)
226
+ instance_exec(new_state.name, triggering_event, *args, **kwargs, &state.on_exit)
227
227
  else
228
228
  hook_name = "on_#{state}_exit"
229
- self.send hook_name, new_state, triggering_event, *args if has_callback?(hook_name)
229
+ self.send hook_name, new_state, triggering_event, *args, **kwargs if has_callback?(hook_name)
230
230
  end
231
231
  end
232
232
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: workflow
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.2
4
+ version: 3.1.0.pre
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vladimir Dobriakov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-05-31 00:00:00.000000000 Z
11
+ date: 2024-05-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rdoc
@@ -16,70 +16,70 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '6.1'
19
+ version: '6.4'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '6.1'
26
+ version: '6.4'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '2.0'
33
+ version: '2.3'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '2.0'
40
+ version: '2.3'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: mocha
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '1.8'
47
+ version: '2.2'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '1.8'
54
+ version: '2.2'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '12.3'
61
+ version: '13.1'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '12.3'
68
+ version: '13.1'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: minitest
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '5.11'
75
+ version: '5.21'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '5.11'
82
+ version: '5.21'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: ruby-graphviz
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -107,9 +107,9 @@ email:
107
107
  executables: []
108
108
  extensions: []
109
109
  extra_rdoc_files:
110
- - README.markdown
110
+ - README.adoc
111
111
  files:
112
- - README.markdown
112
+ - README.adoc
113
113
  - lib/workflow.rb
114
114
  - lib/workflow/draw.rb
115
115
  - lib/workflow/errors.rb
@@ -130,14 +130,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
130
130
  requirements:
131
131
  - - ">="
132
132
  - !ruby/object:Gem::Version
133
- version: '2.3'
133
+ version: '2.7'
134
134
  required_rubygems_version: !ruby/object:Gem::Requirement
135
135
  requirements:
136
- - - ">="
136
+ - - ">"
137
137
  - !ruby/object:Gem::Version
138
- version: '0'
138
+ version: 1.3.1
139
139
  requirements: []
140
- rubygems_version: 3.0.1
140
+ rubygems_version: 3.3.7
141
141
  signing_key:
142
142
  specification_version: 4
143
143
  summary: A replacement for acts_as_state_machine.