rails-workflow 1.4.9 → 1.4.10
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/event.rb +8 -1
- data/lib/workflow/specification.rb +2 -2
- data/lib/workflow/state.rb +11 -7
- 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: 191eec593e88c80dc6841a12868e152969c1a7d9
|
4
|
+
data.tar.gz: 6d3286dc5b0e76ee27f828eacc331ce564614c61
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bc0a5badfa16114e179459339dae2c6878b459c6994b622ceef89470d452fae7b8f16e85b82a2923a356af39c748a6478181753df7acd38a40a96fe9cc61238b
|
7
|
+
data.tar.gz: 5de00112a75831b3de4b1c2aa34ff2e310dbb1616d7bb63075d152855f20adcd070aebc4c9abb1b3f26170d3e971f0bd68d5b1c62a3a87744c0b820d1ba1de2f
|
data/lib/workflow/event.rb
CHANGED
@@ -16,7 +16,7 @@ module Workflow
|
|
16
16
|
# @param [Symbol] name The name of the event to create.
|
17
17
|
# @param [Hash] meta Optional Metadata for this object.
|
18
18
|
# @param [Array] tags Tags for this event.
|
19
|
-
def initialize(name, tags: [], meta
|
19
|
+
def initialize(name, tags: [], **meta)
|
20
20
|
@name = name.to_sym
|
21
21
|
@transitions = []
|
22
22
|
@meta = meta || {}
|
@@ -24,6 +24,13 @@ module Workflow
|
|
24
24
|
unless @tags.reject { |t| t.is_a? Symbol }
|
25
25
|
raise WorkflowDefinitionError, "Tags can only include symbols, event: [#{name}]"
|
26
26
|
end
|
27
|
+
|
28
|
+
meta.each do |meta_name, value|
|
29
|
+
class_eval do
|
30
|
+
attr_accessor meta_name
|
31
|
+
end
|
32
|
+
instance_variable_set("@#{meta_name}", value)
|
33
|
+
end
|
27
34
|
end
|
28
35
|
|
29
36
|
# @return [String] Titleized name of this event.
|
@@ -71,9 +71,9 @@ module Workflow
|
|
71
71
|
# @param [Array] tags Tags to apply to the {Workflow::State} object
|
72
72
|
# @yield [] block defining events for this state.
|
73
73
|
# @return [nil]
|
74
|
-
def state(name, tags: [], meta
|
74
|
+
def state(name, tags: [], **meta, &events)
|
75
75
|
name = name.to_sym
|
76
|
-
new_state = Workflow::State.new(name, @states.length, tags: tags, meta
|
76
|
+
new_state = Workflow::State.new(name, @states.length, tags: tags, **meta)
|
77
77
|
@initial_state ||= new_state
|
78
78
|
@states << new_state
|
79
79
|
new_state.instance_eval(&events) if block_given?
|
data/lib/workflow/state.rb
CHANGED
@@ -10,26 +10,30 @@ module Workflow
|
|
10
10
|
# @return [Symbol] The name of the state.
|
11
11
|
# @!attribute [r] events
|
12
12
|
# @return [Array] Array of {Workflow::Event}s defined for this state.
|
13
|
-
# @!attribute [r] meta
|
14
|
-
# @return [Hash] Extra information defined for this state.
|
15
13
|
# @!attribute [r] tags
|
16
14
|
# @return [Array] Tags for this state.
|
17
|
-
attr_reader :name, :events, :
|
15
|
+
attr_reader :name, :events, :tags
|
18
16
|
|
19
17
|
# @api private
|
20
18
|
# For creating {Workflow::State} objects please see {Specification#state}
|
21
19
|
# @param [Symbol] name Name of the state being created. Must be unique within its workflow.
|
22
20
|
# @param [Fixnum] sequence Sort location among states on this workflow.
|
23
21
|
# @param [Hash] meta Optional metadata for this state.
|
24
|
-
def initialize(name, sequence, tags: [], meta
|
22
|
+
def initialize(name, sequence, tags: [], **meta)
|
25
23
|
@name = name.to_sym
|
26
24
|
@sequence = sequence
|
27
25
|
@events = []
|
28
|
-
@meta = meta
|
29
26
|
@tags = [tags].flatten.uniq
|
30
27
|
unless @tags.reject { |t| t.is_a? Symbol }
|
31
28
|
raise WorkflowDefinitionError, "Tags can only include symbols, state: [#{name}]"
|
32
29
|
end
|
30
|
+
|
31
|
+
meta.each do |meta_name, value|
|
32
|
+
class_eval do
|
33
|
+
attr_accessor meta_name
|
34
|
+
end
|
35
|
+
instance_variable_set("@#{meta_name}", value)
|
36
|
+
end
|
33
37
|
end
|
34
38
|
|
35
39
|
# Returns the event with the given name.
|
@@ -71,9 +75,9 @@ module Workflow
|
|
71
75
|
# state :the_diner
|
72
76
|
# end
|
73
77
|
# ```
|
74
|
-
def on(name, to: nil, tags: [], meta
|
78
|
+
def on(name, to: nil, tags: [], **meta, &transitions)
|
75
79
|
check_can_add_transition!(name, to: to, &transitions)
|
76
|
-
event = Workflow::Event.new(name, tags: tags, meta
|
80
|
+
event = Workflow::Event.new(name, tags: tags, **meta)
|
77
81
|
|
78
82
|
if to
|
79
83
|
event.to to
|
data/lib/workflow/version.rb
CHANGED