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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 191eec593e88c80dc6841a12868e152969c1a7d9
4
- data.tar.gz: 6d3286dc5b0e76ee27f828eacc331ce564614c61
3
+ metadata.gz: b8bdc4bd121ea33bf5c173251fbad21009ddeb72
4
+ data.tar.gz: f593969d04cbb64b74cb551da7e7b06ca7e3fcd6
5
5
  SHA512:
6
- metadata.gz: bc0a5badfa16114e179459339dae2c6878b459c6994b622ceef89470d452fae7b8f16e85b82a2923a356af39c748a6478181753df7acd38a40a96fe9cc61238b
7
- data.tar.gz: 5de00112a75831b3de4b1c2aa34ff2e310dbb1616d7bb63075d152855f20adcd070aebc4c9abb1b3f26170d3e971f0bd68d5b1c62a3a87744c0b820d1ba1de2f
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, keyed by name
12
- # @return [Hash]
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
- events = states.map(&:events).flatten
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
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Workflow
3
- VERSION = '1.4.10'
3
+ VERSION = '1.4.11'
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-workflow
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.10
4
+ version: 1.4.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tyler Gannon