rails-workflow 1.4.4.4 → 1.4.5.4

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.
@@ -1,7 +1,6 @@
1
1
  require 'workflow/state'
2
2
  require 'workflow/event'
3
3
  require 'workflow/errors'
4
- require 'active_support/callbacks'
5
4
 
6
5
  module Workflow
7
6
  # Metadata object describing available states and state transitions.
@@ -51,13 +50,14 @@ module Workflow
51
50
  end
52
51
  end
53
52
 
53
+ # Find the state with the given name.
54
+ #
55
+ # @param [Symbol] name Name of state to find.
56
+ # @return [Workflow::State] The state with the given name.
54
57
  def find_state(name)
55
58
  states.find{|t| t.name == name.to_sym}
56
59
  end
57
60
 
58
-
59
-
60
-
61
61
  # @api private
62
62
  #
63
63
  # @param [Hash] meta Metadata
@@ -79,7 +79,7 @@ module Workflow
79
79
  # @return [nil]
80
80
  def state(name, meta: {}, &events)
81
81
  name = name.to_sym
82
- new_state = Workflow::State.new(name, self, meta)
82
+ new_state = Workflow::State.new(name, @states.length, meta: meta)
83
83
  @initial_state ||= new_state
84
84
  @states << new_state
85
85
  new_state.instance_eval(&events) if block_given?
@@ -110,7 +110,7 @@ module Workflow
110
110
  # workflow do
111
111
  # define_revert_events!
112
112
  # state :foo do
113
- # event :bar, transitions_to: :bax
113
+ # on :bar, to: :bax
114
114
  # end
115
115
  # state :bax
116
116
  # end
@@ -1,14 +1,30 @@
1
1
  module Workflow
2
+ # Represents one state for the defined workflow,
3
+ # with a list of {Workflow::Event}s that can transition to
4
+ # other states.
2
5
  class State
3
6
  include Comparable
4
7
 
5
- attr_accessor :name, :events, :meta, :on_entry, :on_exit
6
- attr_reader :sequence
8
+ # @!attribute [r] name
9
+ # @return [Symbol] The name of the state.
10
+ # @!attribute [r] events
11
+ # @return [Array] Array of {Workflow::Event}s defined for this state.
12
+ # @!attribute [r] meta
13
+ # @return [Hash] Extra information defined for this state.
14
+ attr_reader :name, :events, :meta
7
15
 
8
- def initialize(name, sequence, **meta)
16
+ # @api private
17
+ # For creating {Workflow::State} objects please see {Specification#state}
18
+ # @param [Symbol] name The name of the state being created. Should be unique within its workflow.
19
+ # @param [Fixnum] sequence Sequencing number that will affect sorting comparisons with other states.
20
+ # @param [Hash] meta: Optional metadata for this state.
21
+ def initialize(name, sequence, meta: {})
9
22
  @name, @sequence, @events, @meta = name.to_sym, sequence, [], meta
10
23
  end
11
24
 
25
+ # Returns the event with the given name.
26
+ # @param [Symbol] name name of event to find
27
+ # @return [Workflow::Event] The event with the given name, or `nil`
12
28
  def find_event(name)
13
29
  events.find{|t| t.name == name}
14
30
  end
@@ -17,10 +33,9 @@ module Workflow
17
33
  # Must be called within the scope of the block within a call to {#state}.
18
34
  #
19
35
  # @param [Symbol] name The name of the event
20
- # @param [Hash] args
21
- # @option args [Symbol] :transitions_to The state this event transitions to.
22
- # @option args [Symbol] :if optional instance method name or [Proc] that will receive the object when called.
23
- # @option args [Hash] :meta Optional metadata to be stored on the event object
36
+ # @param [Symbol] to: Optional name of {Workflow::State} this event will transition to. Must be omitted if a block is provided.
37
+ # @param [Hash] meta: Optional hash of metadata to be stored on the event object.
38
+ # @yield [] Transitions definition for this event.
24
39
  # @return [nil]
25
40
  #
26
41
  #```ruby
@@ -45,7 +60,7 @@ module Workflow
45
60
  # state :the_diner
46
61
  #end
47
62
  #```
48
- def on(name, to: nil, meta: nil, &transitions)
63
+ def on(name, to: nil, meta: {}, &transitions)
49
64
  if to && block_given?
50
65
  raise Errors::WorkflowDefinitionError.new("Event target can only be received in the method call or the block, not both.")
51
66
  end
@@ -58,7 +73,7 @@ module Workflow
58
73
  raise Errors::WorkflowDefinitionError.new("Already defined an event [#{name}] for state[#{self.name}]")
59
74
  end
60
75
 
61
- event = Workflow::Event.new(name, meta)
76
+ event = Workflow::Event.new(name, meta: meta)
62
77
 
63
78
  if to
64
79
  event.to to
@@ -74,15 +89,28 @@ module Workflow
74
89
  nil
75
90
  end
76
91
 
92
+ # @return [String] String representation of object
77
93
  def inspect
78
94
  "<State name=#{name.inspect} events(#{events.length})=#{events.inspect}>"
79
95
  end
80
96
 
97
+ # Overloaded comparison operator. Workflow states are sorted according to the order
98
+ # in which they were defined.
99
+ #
100
+ # @param [Workflow::State] other_state state to be compared against.
101
+ # @return [Integer]
81
102
  def <=>(other_state)
82
103
  unless other_state.is_a?(State)
83
104
  raise StandardError.new "Other State #{other_state} is a #{other_state.class}. I can only be compared with a Workflow::State."
84
105
  end
85
- self.sequence <=> other_state.sequence
106
+ self.sequence <=> other_state.send(:sequence)
86
107
  end
108
+
109
+ private
110
+ # @api private
111
+ # @!attribute [r] sequence
112
+ # @return [Fixnum] The position of this state within the order it was defined for in its workflow.
113
+ attr_reader :sequence
114
+
87
115
  end
88
116
  end
@@ -1,3 +1,3 @@
1
1
  module Workflow
2
- VERSION = "1.4.4.4"
2
+ VERSION = "1.4.5.4"
3
3
  end
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
 
11
11
  spec.summary = %q{A finite-state-machine-inspired API for managing state changes in ActiveModel objects. Based on Vladimir Dobriakov's Workflow gem (https://github.com/geekq/workflow)}
12
12
  spec.description = %q{Workflow specifically for ActiveModel objects.}
13
- spec.homepage = "https://github.com/tylergannon/rails-workflow"
13
+ spec.homepage = "https://tylergannon.github.io/rails-workflow/"
14
14
  spec.license = "MIT"
15
15
 
16
16
  # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-workflow
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.4.4
4
+ version: 1.4.5.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tyler Gannon
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-09-24 00:00:00.000000000 Z
11
+ date: 2016-09-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -215,14 +215,16 @@ files:
215
215
  - gemfiles/Gemfile.rails-4.0
216
216
  - gemfiles/Gemfile.rails-5.0
217
217
  - gemfiles/Gemfile.rails-edge
218
+ - lib/active_support/overloads.rb
218
219
  - lib/workflow.rb
219
220
  - lib/workflow/adapters/active_record.rb
220
221
  - lib/workflow/adapters/active_record_validations.rb
221
222
  - lib/workflow/adapters/remodel.rb
222
223
  - lib/workflow/callbacks.rb
223
224
  - lib/workflow/callbacks/callback.rb
224
- - lib/workflow/callbacks/transition_callback_method_wrapper.rb
225
- - lib/workflow/callbacks/transition_callback_wrapper.rb
225
+ - lib/workflow/callbacks/transition_callback.rb
226
+ - lib/workflow/callbacks/transition_callbacks/method_wrapper.rb
227
+ - lib/workflow/callbacks/transition_callbacks/proc_wrapper.rb
226
228
  - lib/workflow/configuration.rb
227
229
  - lib/workflow/draw.rb
228
230
  - lib/workflow/errors.rb
@@ -233,7 +235,7 @@ files:
233
235
  - lib/workflow/version.rb
234
236
  - orders_workflow.png
235
237
  - rails-workflow.gemspec
236
- homepage: https://github.com/tylergannon/rails-workflow
238
+ homepage: https://tylergannon.github.io/rails-workflow/
237
239
  licenses:
238
240
  - MIT
239
241
  metadata:
@@ -1,65 +0,0 @@
1
- module Workflow
2
- module Callbacks
3
- class TransitionCallbackMethodWrapper < TransitionCallbackWrapper
4
- attr_reader :calling_class
5
-
6
- def wrapper
7
- cb_object = self
8
- proc_string = build_proc(<<-EOF)
9
- arguments = [
10
- cb_object.send(:raw_proc).inspect,
11
- cb_object.send(:name_arguments_string),
12
- cb_object.send(:rest_param_string),
13
- cb_object.send(:kw_arguments_string),
14
- cb_object.send(:keyrest_string),
15
- cb_object.send(:procedure_string)].compact.join(', ')
16
- target.instance_eval("send(\#{arguments})")
17
- EOF
18
- p = eval(proc_string)
19
- return overload_equality_operator(p)
20
- end
21
-
22
- # protected
23
-
24
- def overload_equality_operator(outer_proc)
25
- raw_proc = raw_proc
26
- def outer_proc.raw_proc
27
- raw_proc
28
- end
29
- def outer_proc.==(other)
30
- if other.kind_of?(::Proc)
31
- if other.respond_to?(:raw_proc)
32
- self.raw_proc == other.raw_proc
33
- else
34
- self == other
35
- end
36
- elsif other.kind_of?(Symbol)
37
- self.raw_proc == other
38
- else
39
- false
40
- end
41
- end
42
- return outer_proc
43
- end
44
- def name_arguments_string
45
- name_params.map{|name| "name_proc.call(:#{name})"} if name_params.any?
46
- end
47
-
48
- def procedure_string
49
- '&callbacks' if around_callback?
50
- end
51
-
52
- def callback_method
53
- @meth ||= calling_class.instance_method(raw_proc)
54
- end
55
-
56
- def parameters
57
- callback_method.parameters
58
- end
59
-
60
- def arity
61
- callback_method.arity
62
- end
63
- end
64
- end
65
- end