rails-workflow 1.4.9 → 1.4.10

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: a0c0de01bab05a5f8341926e5974b8b3f9c32d1c
4
- data.tar.gz: 29819cf2b683ba967f4afca0777995ec083f46b9
3
+ metadata.gz: 191eec593e88c80dc6841a12868e152969c1a7d9
4
+ data.tar.gz: 6d3286dc5b0e76ee27f828eacc331ce564614c61
5
5
  SHA512:
6
- metadata.gz: 885c16267799c5adb3f13d798107316694e2ef6af456608aecf41ab69b6fd4807ff3a7d0be80e2391a1044af14ceb2ef7077617cec9cb63b2b9da63017ef5365
7
- data.tar.gz: 7b72efe1c43c254edc085628fc91494be94ef0fff2ecfeca245723e226cf90fcd5d800a05831058ec04f83d9b15bf12cae8b1ccedafa16ae8e1db183125b39bb
6
+ metadata.gz: bc0a5badfa16114e179459339dae2c6878b459c6994b622ceef89470d452fae7b8f16e85b82a2923a356af39c748a6478181753df7acd38a40a96fe9cc61238b
7
+ data.tar.gz: 5de00112a75831b3de4b1c2aa34ff2e310dbb1616d7bb63075d152855f20adcd070aebc4c9abb1b3f26170d3e971f0bd68d5b1c62a3a87744c0b820d1ba1de2f
@@ -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: {}, &events)
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: 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?
@@ -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, :meta, :tags
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: {}, &transitions)
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: meta)
80
+ event = Workflow::Event.new(name, tags: tags, **meta)
77
81
 
78
82
  if to
79
83
  event.to to
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Workflow
3
- VERSION = '1.4.9'
3
+ VERSION = '1.4.10'
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.9
4
+ version: 1.4.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tyler Gannon