rails-workflow 1.4.6.4 → 1.4.8.4

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: 5aea9261c6bf6fa5ab1c793179ef8440a67be0d6
4
- data.tar.gz: aa69e4c243b24250f6880cfcfcf3efafc33b9a15
3
+ metadata.gz: 41958ff514ac9776a7dcdc9a4ca9bdeff19c5207
4
+ data.tar.gz: 7503bd6d628ea7a37576db536a7dc57342d208ea
5
5
  SHA512:
6
- metadata.gz: ad8375bdbe64ae0ddadf8d9e272e22d198dfc87108327fba67d7c2852955c334334efafe24195b4f0d6ffe2d18ce726205fff343142a8c2cbe46c0e44721988e
7
- data.tar.gz: ccb120fe43028613ab269556076cbee0a7113da2831d0c32308cd68a680080e99fc21e68b50142f8843bb57813fe67d82facc0bfa1d387e6eabac5ad2c40287c
6
+ metadata.gz: 9037c414fa9d537ec00bd97d22b18330531bb5cd6af225bd62c45df00fe62249ffce6acdd39ca194d135e83dc949089f9882dceba4f78a73ef059f93779251a9
7
+ data.tar.gz: ba52069e35a1637a99f4631492bd9dfe816f93a81aa42d751dfb9739c2295ce4e7183524b9c35a2afc051d422f19b11a2705878ed804c39560c0a8bef4abdba2
@@ -7,16 +7,23 @@ module Workflow
7
7
  # @return [Array] Array of {Workflow::Event::Transition}s defined for this event.
8
8
  # @!attribute [r] meta
9
9
  # @return [Hash] Extra information defined for this event.
10
- attr_reader :name, :transitions, :meta
10
+ # @!attribute [r] tags
11
+ # @return [Array] Tags for this event.
12
+ attr_reader :name, :transitions, :meta, :tags
11
13
 
12
14
  # @api private
13
15
  # See {Workflow::State#on} for creating objects of this class.
14
16
  # @param [Symbol] name The name of the event to create.
15
17
  # @param [Hash] meta Optional Metadata for this object.
16
- def initialize(name, meta: {})
18
+ # @param [Array] tags Tags for this event.
19
+ def initialize(name, tags: [], meta: {})
17
20
  @name = name.to_sym
18
21
  @transitions = []
19
22
  @meta = meta || {}
23
+ @tags = [tags].flatten.uniq
24
+ unless @tags.reject { |t| t.is_a? Symbol }
25
+ raise WorkflowDefinitionError, "Tags can only include symbols, event: [#{name}]"
26
+ end
20
27
  end
21
28
 
22
29
  def valid?
@@ -41,6 +41,7 @@ module Workflow
41
41
  end
42
42
 
43
43
  set_callback(:spec_definition, :after, :define_tag_methods)
44
+ set_callback(:spec_definition, :after, :define_event_tag_methods)
44
45
 
45
46
  # Find the state with the given name.
46
47
  #
@@ -126,7 +127,7 @@ module Workflow
126
127
 
127
128
  private
128
129
 
129
- module TagHelpers
130
+ module StateTagHelpers
130
131
  def initial?
131
132
  sequence.zero?
132
133
  end
@@ -138,15 +139,24 @@ module Workflow
138
139
 
139
140
  def define_tag_methods
140
141
  tags = states.map(&:tags).flatten.uniq
141
- tag_method_module = build_tag_method_module(tags)
142
+ tag_method_module = build_tag_method_module(tags, true)
142
143
  states.each do |state|
143
144
  state.send :extend, tag_method_module
144
145
  end
145
146
  end
146
147
 
147
- def build_tag_method_module(tags)
148
+ def define_event_tag_methods
149
+ events = states.map(&:events).flatten
150
+ tags = events.map(&:tags).flatten
151
+ tag_method_module = build_tag_method_module(tags, false)
152
+ events.each do |event|
153
+ event.send :extend, tag_method_module
154
+ end
155
+ end
156
+
157
+ def build_tag_method_module(tags, include_state_helpers)
148
158
  tag_method_module = Module.new
149
- tag_method_module.send :include, TagHelpers
159
+ tag_method_module.send :include, StateTagHelpers if include_state_helpers
150
160
  tag_method_module.class_eval do
151
161
  tags.each do |tag|
152
162
  define_method "#{tag}?" do
@@ -26,9 +26,9 @@ module Workflow
26
26
  @sequence = sequence
27
27
  @events = []
28
28
  @meta = meta
29
- @tags = [tags].flatten
29
+ @tags = [tags].flatten.uniq
30
30
  unless @tags.reject { |t| t.is_a? Symbol }
31
- raise WorkflowDefinitionError, "Tags can only include symbols, state: #{name}"
31
+ raise WorkflowDefinitionError, "Tags can only include symbols, state: [#{name}]"
32
32
  end
33
33
  end
34
34
 
@@ -71,9 +71,9 @@ module Workflow
71
71
  # state :the_diner
72
72
  # end
73
73
  # ```
74
- def on(name, to: nil, meta: {}, &transitions)
74
+ def on(name, to: nil, tags: [], meta: {}, &transitions)
75
75
  check_can_add_transition!(name, to: to, &transitions)
76
- event = Workflow::Event.new(name, meta: meta)
76
+ event = Workflow::Event.new(name, tags: tags, meta: meta)
77
77
 
78
78
  if to
79
79
  event.to to
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Workflow
3
- VERSION = '1.4.6.4'
3
+ VERSION = '1.4.8.4'
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.6.4
4
+ version: 1.4.8.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tyler Gannon