aasm 4.12.1 → 4.12.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 51fca1a6911cbe2585301606192b2d0a467ae7e7
4
- data.tar.gz: c4bdfee904a029cec8329eb024c608f225a3b746
3
+ metadata.gz: 13bde38e3731e93db61f6058f32cba8a1a1f6fa0
4
+ data.tar.gz: a5ab477ba4a18e4e90d2d61c9010421fb39e2011
5
5
  SHA512:
6
- metadata.gz: 7ce9707a179a75f5e75c038ae8102956503564bca475151a6c64dfad9862b313382fc6b7f3ddc2c8e928dfbb666667b171be5abc7bf7d569e5e72cd4ee59467e
7
- data.tar.gz: e2c030b9c239c3ced525745ed32f192712ed946fff5f5ed45c8c2710fe3da2aa8291f41faf351b9241c1eb7e6ecf4bb4ad72aace93aeb6f91e0b8af58d253f73
6
+ metadata.gz: f51ca4fab23d2e61bdb392ae49a63b2a003a6de07251e39c8dcab892e2282073ed420f35c9bf131f2261ed68bd7d4fdbabd338acd5dbe4ec7f98e1eefaa6c757
7
+ data.tar.gz: a4eb3ffcceee128b4b3f33bc9e27d69993887a4f7ce2d56a0d4fa0541f154eb3c7cb16d2d9b75a9c4f86fced4af73cf9415b90ca5dd3fcd3d79f3cd81fa981ad
data/Appraisals CHANGED
@@ -37,10 +37,7 @@ appraise 'rails_5.0' do
37
37
  gem 'rails', '5.0.0'
38
38
  gem 'mongoid', '~>6.0'
39
39
  gem 'sequel'
40
-
41
- # dynamoid is not yet Rails 5 compatible
42
- # gem 'dynamoid', '~> 1', :platforms => :ruby
43
-
40
+ gem 'dynamoid', '~> 1', :platforms => :ruby
44
41
  gem 'aws-sdk', '~>2', :platforms => :ruby
45
42
  gem 'redis-objects'
46
43
  end
@@ -1,12 +1,17 @@
1
1
  # CHANGELOG
2
2
 
3
3
  ## unreleased
4
+ ## 4.12.2
5
+
6
+ * Fix guards parameter [#484](https://github.com/aasm/aasm/pull/484), thanks to [teohm](https://github.com/teohm)
7
+ * Make errors more inspectable [#452](https://github.com/aasm/aasm/pull/452), thanks to [flexoid](https://github.com/flexoid)
8
+ * Enable Dynamoid for Rails 5 [#483](https://github.com/aasm/aasm/pull/483), thanks to [focusshifter](https://github.com/focusshifter)
4
9
 
5
10
  ## 4.12.1
6
11
 
7
- * DRY-up Mongoid and ActiveRecord Persistence, Add Sequel transactions and locking #475, thanks to [@Aryk] (https://github.com/Aryk)
8
- * Add aliases for event methods #476, thanks to [@Aryk] (https://github.com/Aryk)
9
- * Support Minitest spec expectations (#387), thanks to [@faragorn] (https://github.com/faragorn)
12
+ * DRY-up Mongoid and ActiveRecord Persistence, Add Sequel transactions and locking [#475](https://github.com/aasm/aasm/pull/475), thanks to [@Aryk] (https://github.com/Aryk)
13
+ * Add aliases for event methods [#476](https://github.com/aasm/aasm/pull/476), thanks to [@Aryk] (https://github.com/Aryk)
14
+ * Support Minitest spec expectations [#387](https://github.com/aasm/aasm/pull/387), thanks to [@faragorn] (https://github.com/faragorn)
10
15
  ## 4.12.0
11
16
 
12
17
  * Fix thread safe issue with concurrent-ruby gem [see [pull-request #422](https://github.com/aasm/aasm/pull/442), thanks to [@reidmorrison](https://github.com/reidmorrison)
data/README.md CHANGED
@@ -165,37 +165,6 @@ class LogRunTime
165
165
  end
166
166
  ```
167
167
 
168
- Here you can see a list of all possible callbacks, together with their order of calling:
169
-
170
- ```ruby
171
- begin
172
- event before_all_events
173
- event before
174
- event guards
175
- transition guards
176
- old_state before_exit
177
- old_state exit
178
- after_all_transitions
179
- transition after
180
- new_state before_enter
181
- new_state enter
182
- ...update state...
183
- event before_success # if persist successful
184
- transition success # if persist successful
185
- event success # if persist successful
186
- old_state after_exit
187
- new_state after_enter
188
- event after
189
- event after_all_events
190
- rescue
191
- event error
192
- event error_on_all_events
193
- ensure
194
- event ensure
195
- event ensure_on_all_events
196
- end
197
- ```
198
-
199
168
  Also, you can pass parameters to events:
200
169
 
201
170
  ```ruby
@@ -228,6 +197,39 @@ and the target state (the to state), like this:
228
197
  end
229
198
  ```
230
199
 
200
+ #### Lifecycle
201
+
202
+ Here you can see a list of all possible callbacks, together with their order of calling:
203
+
204
+ ```ruby
205
+ begin
206
+ event before_all_events
207
+ event before
208
+ event guards
209
+ transition guards
210
+ old_state before_exit
211
+ old_state exit
212
+ after_all_transitions
213
+ transition after
214
+ new_state before_enter
215
+ new_state enter
216
+ ...update state...
217
+ event before_success # if persist successful
218
+ transition success # if persist successful
219
+ event success # if persist successful
220
+ old_state after_exit
221
+ new_state after_enter
222
+ event after
223
+ event after_all_events
224
+ rescue
225
+ event error
226
+ event error_on_all_events
227
+ ensure
228
+ event ensure
229
+ event ensure_on_all_events
230
+ end
231
+ ```
232
+
231
233
  #### The current event triggered
232
234
 
233
235
  While running the callbacks you can easily retrieve the name of the event triggered
@@ -280,11 +282,19 @@ class Cleaner
280
282
  end
281
283
  transitions :from => :idle, :to => :idle
282
284
  end
285
+
286
+ event :clean_if_dirty do
287
+ transitions :from => :idle, :to => :cleaning, :guard => :if_dirty?
288
+ end
283
289
  end
284
290
 
285
291
  def cleaning_needed?
286
292
  false
287
293
  end
294
+
295
+ def if_dirty?(status)
296
+ status == :dirty
297
+ end
288
298
  end
289
299
 
290
300
  job = Cleaner.new
@@ -292,6 +302,9 @@ job.may_clean? # => false
292
302
  job.clean # => raises AASM::InvalidTransition
293
303
  job.may_clean_if_needed? # => true
294
304
  job.clean_if_needed! # idle
305
+
306
+ job.clean_if_dirty(:clean) # => false
307
+ job.clean_if_dirty(:dirty) # => true
295
308
  ```
296
309
 
297
310
  You can even provide a number of guards, which all have to succeed to proceed
@@ -1016,6 +1029,8 @@ class Job
1016
1029
  end
1017
1030
  ```
1018
1031
 
1032
+ You can hide warnings by setting `AASM::Configuration.hide_warnings = true`
1033
+
1019
1034
  ### RubyMotion support
1020
1035
 
1021
1036
  Now supports [CodeDataQuery](https://github.com/infinitered/cdq.git) !
@@ -7,6 +7,7 @@ gem "activerecord-jdbcsqlite3-adapter", :platforms => :jruby
7
7
  gem "rails", "5.0.0"
8
8
  gem "mongoid", "~>6.0"
9
9
  gem "sequel"
10
+ gem "dynamoid", "~> 1", :platforms => :ruby
10
11
  gem "aws-sdk", "~>2", :platforms => :ruby
11
12
  gem "redis-objects"
12
13
 
@@ -1,4 +1,6 @@
1
1
  module AASM
2
+ # this is used internally as an argument default value to represent no value
3
+ NO_VALUE = :_aasm_no_value
2
4
 
3
5
  # provide a state machine for the including class
4
6
  # make sure to load class methods as well
@@ -40,11 +40,11 @@ module AASM::Core
40
40
  # a neutered version of fire - it doesn't actually fire the event, it just
41
41
  # executes the transition guards to determine if a transition is even
42
42
  # an option given current conditions.
43
- def may_fire?(obj, to_state=nil, *args)
43
+ def may_fire?(obj, to_state=::AASM::NO_VALUE, *args)
44
44
  _fire(obj, {:test_only => true}, to_state, *args) # true indicates test firing
45
45
  end
46
46
 
47
- def fire(obj, options={}, to_state=nil, *args)
47
+ def fire(obj, options={}, to_state=::AASM::NO_VALUE, *args)
48
48
  _fire(obj, options, to_state, *args) # false indicates this is not a test (fire!)
49
49
  end
50
50
 
@@ -121,20 +121,19 @@ module AASM::Core
121
121
  definitions
122
122
  end
123
123
 
124
- def _fire(obj, options={}, to_state=nil, *args)
124
+ def _fire(obj, options={}, to_state=::AASM::NO_VALUE, *args)
125
125
  result = options[:test_only] ? false : nil
126
126
  transitions = @transitions.select { |t| t.from == obj.aasm(state_machine.name).current_state || t.from == nil}
127
127
  return result if transitions.size == 0
128
128
 
129
- # If to_state is not nil it either contains a potential
130
- # to_state or an arg
131
- unless to_state == nil
132
- if !to_state.respond_to?(:to_sym) || !transitions.map(&:to).flatten.include?(to_state.to_sym)
133
- args.unshift(to_state)
134
- to_state = nil
135
- end
129
+ if to_state == ::AASM::NO_VALUE
130
+ to_state = nil
131
+ elsif to_state.respond_to?(:to_sym) && transitions.map(&:to).flatten.include?(to_state.to_sym)
132
+ # nop, to_state is a valid to-state
136
133
  else
137
- args.unshift(nil) if args.nil? || args.empty? # If single arg given which is nil, push it back to args
134
+ # to_state is an argument
135
+ args.unshift(to_state)
136
+ to_state = nil
138
137
  end
139
138
 
140
139
  transitions.each do |transition|
@@ -69,7 +69,7 @@ module AASM::Core
69
69
 
70
70
  case code
71
71
  when Symbol, String
72
- result = (record.__send__(:method, code.to_sym).arity != 0 ? record.__send__(code, *args) : record.__send__(code))
72
+ result = (record.__send__(:method, code.to_sym).arity == 0 ? record.__send__(code) : record.__send__(code, *args))
73
73
  failures << code unless result
74
74
  result
75
75
  when Proc
@@ -7,10 +7,7 @@ module AASM
7
7
 
8
8
  def initialize(object, event_name, state_machine_name, failures = [])
9
9
  @object, @event_name, @originating_state, @failures = object, event_name, object.aasm(state_machine_name).current_state, failures
10
- end
11
-
12
- def message
13
- "Event '#{event_name}' cannot transition from '#{originating_state}'. #{reasoning}"
10
+ super("Event '#{event_name}' cannot transition from '#{originating_state}'. #{reasoning}")
14
11
  end
15
12
 
16
13
  def reasoning
@@ -1,3 +1,3 @@
1
1
  module AASM
2
- VERSION = "4.12.1"
2
+ VERSION = "4.12.2"
3
3
  end
@@ -0,0 +1,17 @@
1
+ class GuardArgumentsCheck
2
+ include AASM
3
+
4
+ aasm do
5
+ state :new, :reviewed, :finalized
6
+
7
+ event :mark_as_reviewed,
8
+ :guard => proc { |*args| arguments_list(*args) } do
9
+ transitions :from => :new, :to => :reviewed
10
+ end
11
+ end
12
+
13
+ def arguments_list(arg1, arg2)
14
+ return false unless arg1.nil?
15
+ true
16
+ end
17
+ end
@@ -30,14 +30,14 @@ describe 'when being unsuspended' do
30
30
  it 'should be able to be unsuspended into active if polite' do
31
31
  auth.suspend!
32
32
  expect(auth.may_wait?(:waiting, :please)).to be true
33
- auth.wait!(nil, :please)
33
+ auth.wait!(:please)
34
34
  end
35
35
 
36
36
  it 'should not be able to be unsuspended into active if not polite' do
37
37
  auth.suspend!
38
38
  expect(auth.may_wait?(:waiting)).not_to be true
39
39
  expect(auth.may_wait?(:waiting, :rude)).not_to be true
40
- expect {auth.wait!(nil, :rude)}.to raise_error(AASM::InvalidTransition)
40
+ expect {auth.wait!(:rude)}.to raise_error(AASM::InvalidTransition)
41
41
  expect {auth.wait!}.to raise_error(AASM::InvalidTransition)
42
42
  end
43
43
 
@@ -39,18 +39,18 @@ describe 'when being unsuspended' do
39
39
  it 'should be able to wait into waiting if polite' do
40
40
  auth.left_suspend!
41
41
  expect(auth.may_left_wait?(:waiting, :please)).to be true
42
- auth.left_wait!(nil, :please)
42
+ auth.left_wait!(:please)
43
43
 
44
44
  auth.right_suspend!
45
45
  expect(auth.may_right_wait?(:waiting)).to be false
46
- auth.right_wait!(nil, :please)
46
+ auth.right_wait!(:please)
47
47
  end
48
48
 
49
49
  it 'should not be able to be unsuspended into active if not polite' do
50
50
  auth.left_suspend!
51
51
  expect(auth.may_left_wait?(:waiting)).not_to be true
52
52
  expect(auth.may_left_wait?(:waiting, :rude)).not_to be true
53
- expect {auth.left_wait!(nil, :rude)}.to raise_error(AASM::InvalidTransition)
53
+ expect {auth.left_wait!(:rude)}.to raise_error(AASM::InvalidTransition)
54
54
  expect {auth.left_wait!}.to raise_error(AASM::InvalidTransition)
55
55
  end
56
56
 
@@ -37,7 +37,7 @@ describe 'parametrised events' do
37
37
  end
38
38
 
39
39
  it 'should transition to default state when :after transition invoked' do
40
- pe.dress!(nil, 'purple', 'dressy')
40
+ pe.dress!('purple', 'dressy')
41
41
  expect(pe.aasm(:left).current_state).to eq(:working)
42
42
  end
43
43
 
@@ -106,7 +106,7 @@ describe 'firing an event' do
106
106
  obj = double('object', :aasm => double('aasm', :current_state => :open))
107
107
  expect(obj).to receive(:guard_fn).with('arg1', 'arg2').and_return(true)
108
108
 
109
- expect(event.fire(obj, {}, nil, 'arg1', 'arg2')).to eq(:closed)
109
+ expect(event.fire(obj, {}, 'arg1', 'arg2')).to eq(:closed)
110
110
  end
111
111
 
112
112
  context 'when given a gaurd proc' do
@@ -118,7 +118,7 @@ describe 'firing an event' do
118
118
  line_number = __LINE__ - 2
119
119
  obj = double('object', :aasm => double('aasm', :current_state => :student))
120
120
 
121
- event.fire(obj, {}, nil)
121
+ event.fire(obj, {})
122
122
  expect(event.failed_callbacks).to eq ["#{__FILE__}##{line_number}"]
123
123
  end
124
124
  end
@@ -133,7 +133,7 @@ describe 'firing an event' do
133
133
  obj = double('object', :aasm => double('aasm', :current_state => :student))
134
134
  allow(obj).to receive(:paid_tuition?).and_return(false)
135
135
 
136
- event.fire(obj, {}, nil)
136
+ event.fire(obj, {})
137
137
  expect(event.failed_callbacks).to eq [:paid_tuition?]
138
138
  end
139
139
  end
@@ -315,7 +315,7 @@ describe 'parametrised events' do
315
315
  end
316
316
 
317
317
  it 'should transition to default state when :after transition invoked' do
318
- pe.dress!(nil, 'purple', 'dressy')
318
+ pe.dress!('purple', 'dressy')
319
319
  expect(pe.aasm.current_state).to eq(:working)
320
320
  end
321
321
 
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+
3
+ describe "nil as first argument" do
4
+ let(:guard) { GuardArgumentsCheck.new }
5
+
6
+ it 'does not raise errors' do
7
+ expect { guard.mark_as_reviewed(nil, 'second arg') }.not_to raise_error
8
+ end
9
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aasm
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.12.1
4
+ version: 4.12.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thorsten Boettger
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-07-18 00:00:00.000000000 Z
12
+ date: 2017-08-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: concurrent-ruby
@@ -234,6 +234,7 @@ files:
234
234
  - spec/models/dynamoid/dynamoid_simple.rb
235
235
  - spec/models/foo.rb
236
236
  - spec/models/foo_callback_multiple.rb
237
+ - spec/models/guard_arguments_check.rb
237
238
  - spec/models/guard_with_params.rb
238
239
  - spec/models/guard_with_params_multiple.rb
239
240
  - spec/models/guardian.rb
@@ -298,6 +299,7 @@ files:
298
299
  - spec/unit/event_naming_spec.rb
299
300
  - spec/unit/event_spec.rb
300
301
  - spec/unit/exception_spec.rb
302
+ - spec/unit/guard_arguments_check_spec.rb
301
303
  - spec/unit/guard_multiple_spec.rb
302
304
  - spec/unit/guard_spec.rb
303
305
  - spec/unit/guard_with_params_multiple_spec.rb
@@ -356,7 +358,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
356
358
  version: '0'
357
359
  requirements: []
358
360
  rubyforge_project:
359
- rubygems_version: 2.5.1
361
+ rubygems_version: 2.6.12
360
362
  signing_key:
361
363
  specification_version: 4
362
364
  summary: State machine mixin for Ruby objects
@@ -414,6 +416,7 @@ test_files:
414
416
  - spec/models/dynamoid/dynamoid_simple.rb
415
417
  - spec/models/foo.rb
416
418
  - spec/models/foo_callback_multiple.rb
419
+ - spec/models/guard_arguments_check.rb
417
420
  - spec/models/guard_with_params.rb
418
421
  - spec/models/guard_with_params_multiple.rb
419
422
  - spec/models/guardian.rb
@@ -478,6 +481,7 @@ test_files:
478
481
  - spec/unit/event_naming_spec.rb
479
482
  - spec/unit/event_spec.rb
480
483
  - spec/unit/exception_spec.rb
484
+ - spec/unit/guard_arguments_check_spec.rb
481
485
  - spec/unit/guard_multiple_spec.rb
482
486
  - spec/unit/guard_spec.rb
483
487
  - spec/unit/guard_with_params_multiple_spec.rb