aasm 3.0.24 → 3.0.25

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: 0a95f430c49bb639c7f0df66dc4ce2998636ef6a
4
- data.tar.gz: 67293708b7b6fbaae038e97d229367d0ca074aa8
3
+ metadata.gz: 2d749826eeac0c51c3ee50f09e7acee8f67db5bf
4
+ data.tar.gz: 7c96c771d9470db46c96c0ca1af339afd037feb1
5
5
  SHA512:
6
- metadata.gz: 90707f9d64e5e03e9b58acde6081c9fe5239ff5599ece71a1909abad871dfdb99dfe8d1d63fae89a94d6f5a908754649387cb792f150d09a94f3a3acab2f2714
7
- data.tar.gz: 20f34ec847d1fe22c59a7e077c5ccdd54f5ab6483dbab086544c7f7995f8df408a018344248ed9017ce9f8ed23f5d64dfe549855700d68c8797911edae9ceafc
6
+ metadata.gz: ff4157e4b1824c00a0201d249bd2e3d97f899c172c2209765ce786d0974836291c532a5d8c6ff54d92e999d322a545db3156331b9f69d9ab7ec60b2b94a35eec
7
+ data.tar.gz: e96dffe3354bbe7b9d9a38e0b5f7f1c447effd552e6a98b84bfbcea0ad4fe13299b99f8cffd99bdec42d87b56f3e8940b80744d889d1bb1d84862b133fc633de
@@ -1,11 +1,29 @@
1
1
  language: ruby
2
+
2
3
  rvm:
3
4
  - 1.8.7
4
5
  - 1.9.2
5
6
  - 1.9.3
6
7
  - 2.0.0
7
8
  # - jruby-18mode # JRuby in 1.8 mode
8
- # - jruby-19mode # JRuby in 1.9 mode
9
- - rbx-18mode
10
- - rbx-19mode
9
+ - jruby-19mode # JRuby in 1.9 mode
10
+ - rbx-2.2.1
11
+
11
12
  services: mongodb
13
+
14
+ gemfile:
15
+ - gemfiles/rails_3.2.gemfile
16
+ - gemfiles/rails_4.0.gemfile
17
+
18
+ matrix:
19
+ allow_failures:
20
+ - rvm: rbx-2.2.1
21
+ - rvm: jruby-19mode
22
+ exclude:
23
+ - { rvm: 1.8.7, gemfile: gemfiles/rails_4.0.gemfile }
24
+ - { rvm: 1.9.2, gemfile: gemfiles/rails_4.0.gemfile }
25
+ - { rvm: 1.9.3, gemfile: gemfiles/rails_4.0.gemfile }
26
+ - { rvm: jruby-19mode, gemfile: gemfiles/rails_3.2.gemfile }
27
+ - { rvm: jruby-19mode, gemfile: gemfiles/rails_4.0.gemfile }
28
+ - { rvm: rbx-2.2.1, gemfile: gemfiles/rails_3.2.gemfile }
29
+ - { rvm: rbx-2.2.1, gemfile: gemfiles/rails_4.0.gemfile }
@@ -1,5 +1,13 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 3.1.0 (not yet released)
4
+
5
+ * deprecated old aasm_* class methods (old-style DSL), in preparation for AASM v4.0.0
6
+
7
+ ## 3.0.25
8
+
9
+ * initialize the state even if validation is skipped (for ActiveRecord and Mongoid persistence) (see issue #103, thanks to [@vfonic](https://github.com/vfonic) and [@aaronklaassen](https://github.com/aaronklaassen))
10
+
3
11
  ## 3.0.24
4
12
 
5
13
  * added support for event blocks (thanks to [@Intrepidd](https://github.com/Intrepidd))
data/Gemfile CHANGED
@@ -1,3 +1,11 @@
1
- source 'https://rubygems.org'
1
+ source "https://rubygems.org"
2
+
3
+ gem "sqlite3", :platforms => :ruby
4
+ gem "coveralls", :platforms => :ruby
5
+ gem 'rubysl', :platforms => :rbx
6
+ gem "jruby-openssl", :platforms => :jruby
7
+ gem "activerecord-jdbcsqlite3-adapter", :platforms => :jruby
8
+ gem "rails", "3.2.15"
9
+ gem 'mongoid' if Gem::Version.create(RUBY_VERSION.dup) >= Gem::Version.create('1.9.3')
2
10
 
3
11
  gemspec
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2006-2012 Scott Barron
1
+ Copyright (c) 2006-2014 Scott Barron
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -257,6 +257,7 @@ to include Mongoid::Document before you include AASM.
257
257
  class Job
258
258
  include Mongoid::Document
259
259
  include AASM
260
+ field :aasm_state
260
261
  aasm do
261
262
  ...
262
263
  end
@@ -325,9 +326,9 @@ class Job < ActiveRecord::Base
325
326
 
326
327
  aasm do
327
328
  state :sleeping, :initial => true
328
- state :running
329
+ state :running, :after_commit => :notify_about_running_job
329
330
 
330
- event :run, :after_commit => :notify_about_running_job do
331
+ event :run do
331
332
  transitions :from => :sleeping, :to => :running
332
333
  end
333
334
  end
@@ -417,7 +418,7 @@ gem 'aasm'
417
418
 
418
419
  ## Latest changes ##
419
420
 
420
- Look at the [CHANGELOG](https://github.com/aasm/aasm/blob/master/CHANGELOG.md) for details.
421
+ Take a look at the [CHANGELOG](https://github.com/aasm/aasm/blob/master/CHANGELOG.md) for details about recent changes to the current version.
421
422
 
422
423
  ## Questions? ##
423
424
 
@@ -427,11 +428,11 @@ Feel free to
427
428
  * [ask a question on StackOverflow](http://stackoverflow.com) (tag with `aasm`)
428
429
  * send us a tweet [@aasm](http://twitter.com/aasm)
429
430
 
430
- ## Authors ##
431
+ ## Maintainers ##
431
432
 
432
- * [Scott Barron](https://github.com/rubyist)
433
- * [Travis Tilley](https://github.com/ttilley)
434
- * [Thorsten Böttger](http://github.com/alto)
433
+ * [Scott Barron](https://github.com/rubyist) (2006–2009, original author)
434
+ * [Travis Tilley](https://github.com/ttilley) (2009–2011)
435
+ * [Thorsten Böttger](http://github.com/alto) (since 2011)
435
436
 
436
437
 
437
438
  ## Warranty ##
@@ -443,7 +444,7 @@ purpose.
443
444
 
444
445
  ## License ##
445
446
 
446
- Copyright (c) 2006-2012 Scott Barron
447
+ Copyright (c) 2006-2014 Scott Barron
447
448
 
448
449
  Permission is hereby granted, free of charge, to any person obtaining
449
450
  a copy of this software and associated documentation files (the
@@ -13,22 +13,21 @@ Gem::Specification.new do |s|
13
13
  s.date = Time.now
14
14
  s.licenses = ["MIT"]
15
15
 
16
- s.add_development_dependency 'activerecord', '3.2.15'
16
+ # s.add_development_dependency 'activerecord', '3.2.15'
17
17
  # s.add_development_dependency 'activerecord', '4.0.1'
18
18
 
19
- s.add_development_dependency 'mongoid' if Gem::Version.create(RUBY_VERSION.dup) >= Gem::Version.create('1.9.3')
19
+ # s.add_development_dependency 'mongoid' if Gem::Version.create(RUBY_VERSION.dup) >= Gem::Version.create('1.9.3')
20
20
  s.add_development_dependency 'rake'
21
21
  s.add_development_dependency 'sdoc'
22
22
  s.add_development_dependency 'rspec', '~> 2.14'
23
23
  s.add_development_dependency 'rr'
24
- s.add_development_dependency 'sqlite3'
24
+ # s.add_development_dependency 'sqlite3'
25
25
  s.add_development_dependency 'minitest'
26
26
  # s.add_development_dependency 'debugger'
27
27
  # s.add_development_dependency 'pry'
28
- s.add_development_dependency 'ruby-debug-completion'
29
28
 
30
29
  s.add_development_dependency 'mime-types', '~> 1.25' # needed by coveralls (>= 2.0 needs Ruby >=1.9.2)
31
- s.add_development_dependency 'coveralls'
30
+ # s.add_development_dependency 'coveralls'
32
31
 
33
32
  s.files = `git ls-files`.split("\n")
34
33
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
@@ -0,0 +1,11 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "sqlite3", :platforms => :ruby
4
+ gem "coveralls", :platforms => :ruby
5
+ gem 'rubysl', :platforms => :rbx
6
+ gem "jruby-openssl", :platforms => :jruby
7
+ gem "activerecord-jdbcsqlite3-adapter", :platforms => :jruby
8
+ gem "rails", "3.2.15"
9
+ gem 'mongoid' if Gem::Version.create(RUBY_VERSION.dup) >= Gem::Version.create('1.9.3')
10
+
11
+ gemspec :path => "../"
@@ -0,0 +1,10 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "sqlite3", :platforms => :ruby
4
+ gem "coveralls", :platforms => :ruby
5
+ gem 'rubysl', :platforms => :rbx
6
+ gem "jruby-openssl", :platforms => :jruby
7
+ gem "activerecord-jdbcsqlite3-adapter", :platforms => :jruby
8
+ gem "rails", "4.0.1"
9
+
10
+ gemspec :path => "../"
@@ -13,6 +13,3 @@ require 'ostruct'
13
13
  persistence
14
14
  aasm
15
15
  ).each { |file| require File.join(File.dirname(__FILE__), 'aasm', file) }
16
-
17
- # load the deprecated methods and modules
18
- Dir[File.join(File.dirname(__FILE__), 'aasm', 'deprecated', '*.rb')].sort.each { |f| require File.expand_path(f) }
@@ -26,52 +26,56 @@ module AASM
26
26
  @aasm
27
27
  end
28
28
 
29
- # TODO: maybe better: aasm.initial_state
29
+ # TODO remove this method in v4.0.0
30
30
  def aasm_initial_state(set_state=nil)
31
31
  if set_state
32
- # deprecated way to set the value
32
+ warn ".aasm_initial_state(:name) is deprecated and will be removed in version 4.0.0; please use .aasm.initial_state = :name instead!"
33
33
  AASM::StateMachine[self].initial_state = set_state
34
34
  else
35
+ warn ".aasm_initial_state is deprecated and will be removed in version 4.0.0; please use .aasm.initial_state instead!"
35
36
  AASM::StateMachine[self].initial_state
36
37
  end
37
38
  end
38
39
 
39
- # is this better?: aasm.states.name.from_states
40
+ # TODO remove this method in v4.0.0
40
41
  def aasm_from_states_for_state(state, options={})
41
- if options[:transition]
42
- aasm.events[options[:transition]].transitions_to_state(state).flatten.map(&:from).flatten
43
- else
44
- aasm.events.map {|k,v| v.transitions_to_state(state)}.flatten.map(&:from).flatten
45
- end
42
+ warn ".aasm_from_states_for_state is deprecated and will be removed in version 4.0.0; please use .aasm.from_states_for_state instead!"
43
+ aasm.from_states_for_state(state, options)
46
44
  end
47
45
 
48
- # deprecated
46
+ # TODO remove this method in v4.0.0
49
47
  def aasm_initial_state=(state)
48
+ warn ".aasm_initial_state= is deprecated and will be removed in version 4.0.0"
50
49
  AASM::StateMachine[self].initial_state = state
51
50
  end
52
51
 
53
- # deprecated
52
+ # TODO remove this method in v4.0.0
54
53
  def aasm_state(name, options={})
54
+ warn ".aasm_state is deprecated and will be removed in version 4.0.0; please use .aasm.state instead!"
55
55
  aasm.state(name, options)
56
56
  end
57
57
 
58
- # deprecated
58
+ # TODO remove this method in v4.0.0
59
59
  def aasm_event(name, options = {}, &block)
60
+ warn ".aasm_event is deprecated and will be removed in version 4.0.0; please use .aasm.event instead!"
60
61
  aasm.event(name, options, &block)
61
62
  end
62
63
 
63
- # deprecated
64
+ # TODO remove this method in v4.0.0
64
65
  def aasm_states
66
+ warn ".aasm_states is deprecated and will be removed in version 4.0.0; please use .aasm.states instead!"
65
67
  aasm.states
66
68
  end
67
69
 
68
- # deprecated
70
+ # TODO remove this method in v4.0.0
69
71
  def aasm_events
72
+ warn ".aasm_events is deprecated and will be removed in version 4.0.0; please use .aasm.events instead!"
70
73
  aasm.events
71
74
  end
72
75
 
73
- # deprecated
76
+ # TODO remove this method in v4.0.0
74
77
  def aasm_states_for_select
78
+ warn ".aasm_states_for_select is deprecated and will be removed in version 4.0.0; please use .aasm.states_for_select instead!"
75
79
  aasm.states_for_select
76
80
  end
77
81
 
@@ -103,46 +107,46 @@ module AASM
103
107
  true
104
108
  end
105
109
 
106
- # deprecated
110
+ # TODO remove this method in v4.0.0
107
111
  def aasm_current_state
108
- # warn "#aasm_current_state is deprecated and will be removed in version 3.2.0; please use #aasm.state instead!"
112
+ warn "#aasm_current_state is deprecated and will be removed in version 4.0.0; please use #aasm.current_state instead!"
109
113
  aasm.current_state
110
114
  end
111
115
 
112
- # deprecated
116
+ # TODO remove this method in v4.0.0
113
117
  def aasm_enter_initial_state
114
- # warn "#aasm_enter_initial_state is deprecated and will be removed in version 3.2.0; please use #aasm.enter_initial_state instead!"
118
+ warn "#aasm_enter_initial_state is deprecated and will be removed in version 4.0.0; please use #aasm.enter_initial_state instead!"
115
119
  aasm.enter_initial_state
116
120
  end
117
121
 
118
- # deprecated
122
+ # TODO remove this method in v4.0.0
119
123
  def aasm_events_for_current_state
120
- # warn "#aasm_events_for_current_state is deprecated and will be removed in version 3.2.0; please use #aasm.events instead!"
124
+ warn "#aasm_events_for_current_state is deprecated and will be removed in version 4.0.0; please use #aasm.events(aasm.current_state) instead!"
121
125
  aasm.events(aasm.current_state)
122
126
  end
123
127
 
124
- # deprecated
128
+ # TODO remove this method in v4.0.0
125
129
  def aasm_permissible_events_for_current_state
126
- # warn "#aasm_permissible_events_for_current_state is deprecated and will be removed in version 3.2.0; please use #aasm.permissible_events instead!"
130
+ warn "#aasm_permissible_events_for_current_state is deprecated and will be removed in version 4.0.0; please use #aasm.permissible_events instead!"
127
131
  aasm.permissible_events
128
132
  end
129
133
 
130
- # deprecated
134
+ # TODO remove this method in v4.0.0
131
135
  def aasm_events_for_state(state_name)
132
- # warn "#aasm_events_for_state(state_name) is deprecated and will be removed in version 3.2.0; please use #aasm.events(state_name) instead!"
136
+ warn "#aasm_events_for_state(state_name) is deprecated and will be removed in version 4.0.0; please use #aasm.events(state_name) instead!"
133
137
  aasm.events(state_name)
134
138
  end
135
139
 
136
- # deprecated
140
+ # TODO remove this method in v4.0.0
137
141
  def aasm_human_state
138
- # warn "#aasm_human_state is deprecated and will be removed in version 3.2.0; please use #aasm.human_state instead!"
142
+ warn "#aasm_human_state is deprecated and will be removed in version 4.0.0; please use #aasm.human_state instead!"
139
143
  aasm.human_state
140
144
  end
141
145
 
142
146
  private
143
147
 
144
148
  def aasm_fire_event(event_name, options, *args, &block)
145
- event = self.class.aasm_events[event_name]
149
+ event = self.class.aasm.events[event_name]
146
150
  begin
147
151
  old_state = aasm.state_object_for_name(aasm.current_state)
148
152
  old_state.fire_callbacks(:exit, self)
@@ -25,13 +25,16 @@ module AASM
25
25
  end
26
26
  end
27
27
 
28
- def initial_state
29
- @state_machine.initial_state
28
+ def initial_state(new_initial_state=nil)
29
+ if new_initial_state
30
+ @state_machine.initial_state = new_initial_state
31
+ else
32
+ @state_machine.initial_state
33
+ end
30
34
  end
31
35
 
32
36
  # define a state
33
37
  def state(name, options={})
34
- # @clazz.aasm_state(name, options)
35
38
  @state_machine.add_state(name, @clazz, options)
36
39
  @state_machine.initial_state = name if options[:initial] || !@state_machine.initial_state
37
40
 
@@ -46,8 +49,6 @@ module AASM
46
49
 
47
50
  # define an event
48
51
  def event(name, options={}, &block)
49
- # @clazz.aasm_event(name, options, &block)
50
-
51
52
  @state_machine.events[name] = AASM::Event.new(name, options, &block)
52
53
 
53
54
  # an addition over standard aasm so that, before firing an event, you can ask
@@ -78,5 +79,13 @@ module AASM
78
79
  states.map { |state| state.for_select }
79
80
  end
80
81
 
82
+ def from_states_for_state(state, options={})
83
+ if options[:transition]
84
+ events[options[:transition]].transitions_to_state(state).flatten.map(&:from).flatten
85
+ else
86
+ events.map {|k,v| v.transitions_to_state(state)}.flatten.map(&:from).flatten
87
+ end
88
+ end
89
+
81
90
  end
82
91
  end
@@ -36,9 +36,9 @@ module AASM
36
36
  @transitions.select { |t| t.to == state }
37
37
  end
38
38
 
39
- # deprecated
39
+ # TODO remove this method in v4.0.0
40
40
  def all_transitions
41
- # warn "Event#all_transitions is deprecated and will be removed in version 3.2.0; please use Event#transitions instead!"
41
+ warn "Event#all_transitions is deprecated and will be removed in version 4.0.0; please use Event#transitions instead!"
42
42
  transitions
43
43
  end
44
44
 
@@ -54,6 +54,19 @@ module AASM
54
54
  end
55
55
  end
56
56
 
57
+ ## DSL interface
58
+ def transitions(definitions=nil)
59
+ if definitions # define new transitions
60
+ # Create a separate transition for each from state to the given state
61
+ Array(definitions[:from]).each do |s|
62
+ @transitions << AASM::Transition.new(definitions.merge({:from => s.to_sym}))
63
+ end
64
+ # Create a transition if to is specified without from (transitions from ANY state)
65
+ @transitions << AASM::Transition.new(definitions) if @transitions.empty? && definitions[:to]
66
+ end
67
+ @transitions
68
+ end
69
+
57
70
  private
58
71
 
59
72
  def update(options = {}, &block)
@@ -68,7 +81,7 @@ module AASM
68
81
  def _fire(obj, test, to_state=nil, *args)
69
82
  result = test ? false : nil
70
83
  if @transitions.map(&:from).any?
71
- transitions = @transitions.select { |t| t.from == obj.aasm_current_state }
84
+ transitions = @transitions.select { |t| t.from == obj.aasm.current_state }
72
85
  return result if transitions.size == 0
73
86
  else
74
87
  transitions = @transitions
@@ -106,19 +119,6 @@ module AASM
106
119
  end
107
120
  end
108
121
 
109
- ## DSL interface
110
- def transitions(trans_opts=nil)
111
- if trans_opts # define new transitions
112
- # Create a separate transition for each from state to the given state
113
- Array(trans_opts[:from]).each do |s|
114
- @transitions << AASM::Transition.new(trans_opts.merge({:from => s.to_sym}))
115
- end
116
- # Create a transition if to is specified without from (transitions from ANY state)
117
- @transitions << AASM::Transition.new(trans_opts) if @transitions.empty? && trans_opts[:to]
118
- end
119
- @transitions
120
- end
121
-
122
122
  [:after, :before, :error, :success].each do |callback_name|
123
123
  define_method callback_name do |*args, &block|
124
124
  options[callback_name] = Array(options[callback_name])
@@ -15,7 +15,7 @@ module AASM
15
15
  end
16
16
 
17
17
  def enter_initial_state
18
- state_name = determine_state_name(@instance.class.aasm_initial_state)
18
+ state_name = determine_state_name(@instance.class.aasm.initial_state)
19
19
  state_object = state_object_for_name(state_name)
20
20
 
21
21
  state_object.fire_callbacks(:before_enter, @instance)
@@ -36,6 +36,8 @@ module AASM
36
36
  else
37
37
  base.before_validation_on_create(:aasm_ensure_initial_state)
38
38
  end
39
+ # ensure initial aasm state even when validations are skipped
40
+ base.before_create(:aasm_ensure_initial_state)
39
41
  end
40
42
 
41
43
  module ClassMethods
@@ -71,10 +73,10 @@ module AASM
71
73
  # Writes <tt>state</tt> to the state column and persists it to the database
72
74
  #
73
75
  # foo = Foo.find(1)
74
- # foo.aasm_current_state # => :opened
76
+ # foo.aasm.current_state # => :opened
75
77
  # foo.close!
76
- # foo.aasm_current_state # => :closed
77
- # Foo.find(1).aasm_current_state # => :closed
78
+ # foo.aasm.current_state # => :closed
79
+ # Foo.find(1).aasm.current_state # => :closed
78
80
  #
79
81
  # NOTE: intended to be called from an event
80
82
  def aasm_write_state(state)
@@ -97,13 +99,13 @@ module AASM
97
99
  # Writes <tt>state</tt> to the state column, but does not persist it to the database
98
100
  #
99
101
  # foo = Foo.find(1)
100
- # foo.aasm_current_state # => :opened
102
+ # foo.aasm.current_state # => :opened
101
103
  # foo.close
102
- # foo.aasm_current_state # => :closed
103
- # Foo.find(1).aasm_current_state # => :opened
104
+ # foo.aasm.current_state # => :closed
105
+ # Foo.find(1).aasm.current_state # => :opened
104
106
  # foo.save
105
- # foo.aasm_current_state # => :closed
106
- # Foo.find(1).aasm_current_state # => :closed
107
+ # foo.aasm.current_state # => :closed
108
+ # Foo.find(1).aasm.current_state # => :closed
107
109
  #
108
110
  # NOTE: intended to be called from an event
109
111
  def aasm_write_state_without_persistence(state)