rails-workflow 1.4.13 → 1.4.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/workflow/adapters/active_record_validations.rb +19 -7
- data/lib/workflow/adapters/adapter.rb +3 -0
- data/lib/workflow/specification.rb +2 -2
- data/lib/workflow/state.rb +17 -10
- 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: 17c522c16b567a5a0e909a8b37e46b43dcf46f96
|
4
|
+
data.tar.gz: b585c04ac5f95851b43d537cdf785b480e51aaec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dca5ec08aaf2013e28b68e94d73b14feb136f631c9ed0e1b89cb66c904a6d8b33e0771fcfe5a5cd6b5868d12f9a848b14bb79118c8d46b4bb7b3bde9b79e07d2
|
7
|
+
data.tar.gz: f594cc082be1139d73a79652ff6779d74ec4ecb470e78d143e8032fe0ec7cac2e3f0d71c9917481bc2b89ba62e6abdcf534d489357c71a1180c625f630ed172f
|
@@ -8,7 +8,7 @@ module Workflow
|
|
8
8
|
extend ActiveSupport::Concern
|
9
9
|
|
10
10
|
included do
|
11
|
-
prepend RevalidateOnlyAfterAttributesChange
|
11
|
+
prepend RevalidateOnlyAfterAttributesChange if self < ::ActiveRecord::Base
|
12
12
|
end
|
13
13
|
|
14
14
|
###
|
@@ -21,11 +21,7 @@ module Workflow
|
|
21
21
|
#
|
22
22
|
def method_missing(method, *args, &block)
|
23
23
|
if method.to_s =~ /^transitioning_(from|to|via_event)_([\w_-]+)\?$/
|
24
|
-
|
25
|
-
def #{method}
|
26
|
-
transitioning? direction: '#{$LAST_MATCH_INFO[1]}', state: '#{$LAST_MATCH_INFO[2]}'
|
27
|
-
end
|
28
|
-
"
|
24
|
+
define_transitioning_method(method, *$LAST_MATCH_INFO[1..2])
|
29
25
|
send method
|
30
26
|
else
|
31
27
|
super
|
@@ -108,7 +104,7 @@ module Workflow
|
|
108
104
|
end
|
109
105
|
|
110
106
|
def write_attribute(attr_name, value)
|
111
|
-
@changed_since_validation = true
|
107
|
+
@changed_since_validation = true unless attr_name.to_sym == :workflow_state
|
112
108
|
super
|
113
109
|
end
|
114
110
|
end
|
@@ -131,6 +127,22 @@ module Workflow
|
|
131
127
|
|
132
128
|
private
|
133
129
|
|
130
|
+
def persist_workflow_state(new_state)
|
131
|
+
old_state = current_state.name
|
132
|
+
return_val = super
|
133
|
+
return return_val if valid?
|
134
|
+
super(old_state)
|
135
|
+
false
|
136
|
+
end
|
137
|
+
|
138
|
+
def define_transitioning_method(method, direction, state)
|
139
|
+
class_eval do
|
140
|
+
define_method method do
|
141
|
+
transitioning? direction: direction, state: state
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
134
146
|
def transitioning?(direction:, state:)
|
135
147
|
state = state.to_sym
|
136
148
|
return false unless transition_context
|
@@ -10,6 +10,9 @@ module Workflow
|
|
10
10
|
else
|
11
11
|
if Adapters.const_defined?(:ActiveRecord) && self < ::ActiveRecord::Base
|
12
12
|
include Adapters::ActiveRecord
|
13
|
+
end
|
14
|
+
|
15
|
+
if included_modules.map(&:name).include?('ActiveModel::Validations')
|
13
16
|
include ActiveRecordValidations
|
14
17
|
end
|
15
18
|
|
@@ -89,7 +89,7 @@ module Workflow
|
|
89
89
|
# @return [nil]
|
90
90
|
def state(name, tags: [], **meta, &events)
|
91
91
|
name = name.to_sym
|
92
|
-
new_state = Workflow::State.new(name, @states
|
92
|
+
new_state = Workflow::State.new(name, @states, tags: tags, **meta)
|
93
93
|
@initial_state ||= new_state
|
94
94
|
@states << new_state
|
95
95
|
new_state.instance_eval(&events) if block_given?
|
@@ -145,7 +145,7 @@ module Workflow
|
|
145
145
|
|
146
146
|
module StateTagHelpers
|
147
147
|
def initial?
|
148
|
-
|
148
|
+
all_states.index(self).zero?
|
149
149
|
end
|
150
150
|
|
151
151
|
def terminal?
|
data/lib/workflow/state.rb
CHANGED
@@ -17,11 +17,11 @@ module Workflow
|
|
17
17
|
# @api private
|
18
18
|
# For creating {Workflow::State} objects please see {Specification#state}
|
19
19
|
# @param [Symbol] name Name of the state being created. Must be unique within its workflow.
|
20
|
-
# @param [
|
20
|
+
# @param [Array] all_states All states defined for this workflow, used for sorting.
|
21
21
|
# @param [Hash] meta Optional metadata for this state.
|
22
|
-
def initialize(name,
|
22
|
+
def initialize(name, all_states, tags: [], **meta)
|
23
23
|
@name = name.to_sym
|
24
|
-
@
|
24
|
+
@all_states = all_states
|
25
25
|
@events = []
|
26
26
|
@tags = [tags].flatten.uniq
|
27
27
|
unless @tags.reject { |t| t.is_a? Symbol }
|
@@ -93,6 +93,12 @@ module Workflow
|
|
93
93
|
nil
|
94
94
|
end
|
95
95
|
|
96
|
+
class << self
|
97
|
+
def beyond?(other)
|
98
|
+
-> { current_state > other }
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
96
102
|
private def check_can_add_transition!(name, to: nil)
|
97
103
|
raise Errors::DualEventDefinitionError if to && block_given?
|
98
104
|
|
@@ -111,19 +117,20 @@ module Workflow
|
|
111
117
|
# Overloaded comparison operator. Workflow states are sorted according to the order
|
112
118
|
# in which they were defined.
|
113
119
|
#
|
114
|
-
# @param [Workflow::State] other state to be compared against.
|
120
|
+
# @param [Workflow::State] other state or Symbol name to be compared against.
|
115
121
|
# @return [Integer]
|
116
122
|
def <=>(other)
|
117
|
-
|
118
|
-
|
123
|
+
if other.is_a?(Symbol)
|
124
|
+
other = all_states.find { |state| state.name == other }
|
125
|
+
end
|
126
|
+
all_states.index(self) <=> all_states.index(other)
|
119
127
|
end
|
120
128
|
|
121
129
|
private
|
122
130
|
|
123
131
|
# @api private
|
124
|
-
# @!attribute [r]
|
125
|
-
# @return [
|
126
|
-
|
127
|
-
attr_reader :sequence
|
132
|
+
# @!attribute [r] all_states
|
133
|
+
# @return [Array] All states defined on my workflow. Used for sorting.
|
134
|
+
attr_reader :all_states
|
128
135
|
end
|
129
136
|
end
|
data/lib/workflow/version.rb
CHANGED