rails-workflow 1.4.10 → 1.4.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/workflow/adapters/active_record.rb +12 -0
- data/lib/workflow/specification.rb +30 -4
- data/lib/workflow/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b8bdc4bd121ea33bf5c173251fbad21009ddeb72
|
4
|
+
data.tar.gz: f593969d04cbb64b74cb551da7e7b06ca7e3fcd6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a09a67020266baa7489303f5713e0fb346b8d8b6db32257332d4c96ec599cd7314888d4cb854479f76834c7d8f17f2d6e3249f16c262706162f7f44f9f97e98a
|
7
|
+
data.tar.gz: 4161bb384a19eef51d640ff64e0aefb6c3ff373b92259890b0f47428d81f1a21494c5e39b9a35f2126f2e5dd3df8b6da37347a9bc7e7704079bff86b1a8ff3e6
|
@@ -63,6 +63,18 @@ module Workflow
|
|
63
63
|
workflow_spec.states.each { |state| define_scopes(state) }
|
64
64
|
end
|
65
65
|
|
66
|
+
def state_tagged_with(*tags)
|
67
|
+
states = workflow_spec.states.tagged_with(tags)
|
68
|
+
states.map! { |state| state.name.to_s }
|
69
|
+
where(workflow_state: states)
|
70
|
+
end
|
71
|
+
|
72
|
+
def state_not_tagged_with(*tags)
|
73
|
+
states = workflow_spec.states.tagged_with(tags)
|
74
|
+
states.map! { |state| state.name.to_s }
|
75
|
+
where.not(workflow_state: states)
|
76
|
+
end
|
77
|
+
|
66
78
|
private
|
67
79
|
|
68
80
|
def superclass_workflow
|
@@ -8,10 +8,14 @@ module Workflow
|
|
8
8
|
class Specification
|
9
9
|
include ActiveSupport::Callbacks
|
10
10
|
|
11
|
-
# The state objects defined for this specification
|
12
|
-
# @return [
|
11
|
+
# The state objects defined for this specification
|
12
|
+
# @return [Array]
|
13
13
|
attr_reader :states
|
14
14
|
|
15
|
+
# The event objects defined for this specification
|
16
|
+
# @return [Array]
|
17
|
+
attr_reader :events
|
18
|
+
|
15
19
|
# State object to be given to newly created objects under this workflow.
|
16
20
|
# @return [State]
|
17
21
|
attr_reader :initial_state
|
@@ -40,8 +44,10 @@ module Workflow
|
|
40
44
|
end
|
41
45
|
end
|
42
46
|
|
47
|
+
set_callback(:spec_definition, :after, :add_tagged_with_to_states_and_events)
|
43
48
|
set_callback(:spec_definition, :after, :define_tag_methods)
|
44
49
|
set_callback(:spec_definition, :after, :define_event_tag_methods)
|
50
|
+
set_callback(:spec_definition, :after, :collect_events)
|
45
51
|
|
46
52
|
# Find the state with the given name.
|
47
53
|
#
|
@@ -137,6 +143,18 @@ module Workflow
|
|
137
143
|
end
|
138
144
|
end
|
139
145
|
|
146
|
+
module TaggedWith
|
147
|
+
def tagged_with(*tags)
|
148
|
+
tags = [tags].flatten
|
149
|
+
select { |item| (item.tags & tags).any? }
|
150
|
+
end
|
151
|
+
|
152
|
+
def not_tagged_with(*tags)
|
153
|
+
tags = [tags].flatten
|
154
|
+
reject { |item| (item.tags & tags).any? }
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
140
158
|
def define_tag_methods
|
141
159
|
tags = states.map(&:tags).flatten.uniq
|
142
160
|
tag_method_module = build_tag_method_module(tags, true)
|
@@ -145,15 +163,23 @@ module Workflow
|
|
145
163
|
end
|
146
164
|
end
|
147
165
|
|
166
|
+
def collect_events
|
167
|
+
@events = states.map(&:events).flatten
|
168
|
+
end
|
169
|
+
|
148
170
|
def define_event_tag_methods
|
149
|
-
|
150
|
-
tags = events.map(&:tags).flatten
|
171
|
+
tags = events.map(&:tags).flatten
|
151
172
|
tag_method_module = build_tag_method_module(tags, false)
|
152
173
|
events.each do |event|
|
153
174
|
event.send :extend, tag_method_module
|
154
175
|
end
|
155
176
|
end
|
156
177
|
|
178
|
+
def add_tagged_with_to_states_and_events
|
179
|
+
states.send :extend, TaggedWith
|
180
|
+
events.send :extend, TaggedWith
|
181
|
+
end
|
182
|
+
|
157
183
|
def build_tag_method_module(tags, include_state_helpers)
|
158
184
|
tag_method_module = Module.new
|
159
185
|
tag_method_module.send :include, StateTagHelpers if include_state_helpers
|
data/lib/workflow/version.rb
CHANGED