aasm 3.2.0 → 3.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/CHANGELOG.md +4 -0
- data/aasm.gemspec +1 -1
- data/lib/aasm/aasm.rb +1 -1
- data/lib/aasm/base.rb +10 -11
- data/lib/aasm/event.rb +1 -1
- data/lib/aasm/persistence/base.rb +9 -9
- data/lib/aasm/state.rb +3 -3
- data/lib/aasm/state_machine.rb +14 -10
- data/lib/aasm/version.rb +1 -1
- data/spec/unit/event_spec.rb +17 -0
- data/spec/unit/memory_leak_spec.rb +2 -2
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3953eaa965802447de8e3783a35c91dcc89e87a4
|
4
|
+
data.tar.gz: 1b70e517fc29f1fad325a0a46d126cab2eebf029
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 220319a5169ac9f1928a5beaaacf81c72d47ab3cf972dea079633fcc82ac8bfa3d42c97c0ffa38b9526e1a50b729ba331cc7ae29a1267dddd4d3e9ae52a7cd70
|
7
|
+
data.tar.gz: 0eff6b102e298af64e76e6f71cff21989d260c626efada6ed5dc763d092d351fac20a9696f1882ab8110e535b20897def8c5c7d2c013d7df82e4b6c437590a2f
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,10 @@
|
|
4
4
|
|
5
5
|
* deprecated old aasm_* class methods (old-style DSL), in preparation for AASM v4.0.0
|
6
6
|
|
7
|
+
## 3.2.1
|
8
|
+
|
9
|
+
* bugfix: permissible_events and events did not contain events with an empty "from" transition (see [issue #140](https://github.com/aasm/aasm/issues/140) and [issue #141](https://github.com/aasm/aasm/issues/141), thanks to [@daniel-rikowski](https://github.com/daniel-rikowski))
|
10
|
+
|
7
11
|
## 3.2.0
|
8
12
|
|
9
13
|
* support [Sequel](http://sequel.jeremyevans.net/) (see [issue #119](https://github.com/aasm/aasm/issues/119), thanks to [@godfat](https://github.com/godfat))
|
data/aasm.gemspec
CHANGED
@@ -19,7 +19,7 @@ Gem::Specification.new do |s|
|
|
19
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
|
-
s.add_development_dependency 'rspec', '
|
22
|
+
s.add_development_dependency 'rspec', '~> 2.14'
|
23
23
|
s.add_development_dependency 'rr'
|
24
24
|
# s.add_development_dependency 'sqlite3'
|
25
25
|
s.add_development_dependency 'minitest'
|
data/lib/aasm/aasm.rb
CHANGED
@@ -5,7 +5,7 @@ module AASM
|
|
5
5
|
|
6
6
|
# do not overwrite existing state machines, which could have been created by
|
7
7
|
# inheritance, see class method inherited
|
8
|
-
AASM::StateMachine[base] ||= AASM::StateMachine.new
|
8
|
+
AASM::StateMachine[base] ||= AASM::StateMachine.new
|
9
9
|
|
10
10
|
AASM::Persistence.load_persistence(base)
|
11
11
|
super
|
data/lib/aasm/base.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
module AASM
|
2
2
|
class Base
|
3
3
|
|
4
|
-
def initialize(
|
5
|
-
@
|
6
|
-
@state_machine = AASM::StateMachine[@
|
4
|
+
def initialize(klass, options={}, &block)
|
5
|
+
@klass = klass
|
6
|
+
@state_machine = AASM::StateMachine[@klass]
|
7
7
|
@state_machine.config.column = options[:column].to_sym if options[:column]
|
8
8
|
@options = options
|
9
9
|
|
@@ -30,15 +30,14 @@ module AASM
|
|
30
30
|
|
31
31
|
# define a state
|
32
32
|
def state(name, options={})
|
33
|
-
@state_machine.add_state(name, @
|
34
|
-
@state_machine.initial_state = name if options[:initial] || !@state_machine.initial_state
|
33
|
+
@state_machine.add_state(name, @klass, options)
|
35
34
|
|
36
|
-
@
|
35
|
+
@klass.send(:define_method, "#{name.to_s}?") do
|
37
36
|
aasm.current_state == name
|
38
37
|
end
|
39
38
|
|
40
|
-
unless @
|
41
|
-
@
|
39
|
+
unless @klass.const_defined?("STATE_#{name.to_s.upcase}")
|
40
|
+
@klass.const_set("STATE_#{name.to_s.upcase}", name)
|
42
41
|
end
|
43
42
|
end
|
44
43
|
|
@@ -49,15 +48,15 @@ module AASM
|
|
49
48
|
# an addition over standard aasm so that, before firing an event, you can ask
|
50
49
|
# may_event? and get back a boolean that tells you whether the guard method
|
51
50
|
# on the transition will let this happen.
|
52
|
-
@
|
51
|
+
@klass.send(:define_method, "may_#{name.to_s}?") do |*args|
|
53
52
|
aasm.may_fire_event?(name, *args)
|
54
53
|
end
|
55
54
|
|
56
|
-
@
|
55
|
+
@klass.send(:define_method, "#{name.to_s}!") do |*args, &block|
|
57
56
|
aasm_fire_event(name, {:persist => true}, *args, &block)
|
58
57
|
end
|
59
58
|
|
60
|
-
@
|
59
|
+
@klass.send(:define_method, "#{name.to_s}") do |*args, &block|
|
61
60
|
aasm_fire_event(name, {:persist => false}, *args, &block)
|
62
61
|
end
|
63
62
|
end
|
data/lib/aasm/event.rb
CHANGED
@@ -87,26 +87,26 @@ module AASM
|
|
87
87
|
# make sure to create a (named) scope for each state
|
88
88
|
def state_with_scope(name, *args)
|
89
89
|
state_without_scope(name, *args)
|
90
|
-
if AASM::StateMachine[@
|
91
|
-
if @
|
90
|
+
if AASM::StateMachine[@klass].config.create_scopes && !@klass.respond_to?(name)
|
91
|
+
if @klass.ancestors.map {|klass| klass.to_s}.include?("ActiveRecord::Base")
|
92
92
|
|
93
|
-
conditions = {"#{@
|
93
|
+
conditions = {"#{@klass.table_name}.#{@klass.aasm_column}" => name.to_s}
|
94
94
|
if ActiveRecord::VERSION::MAJOR >= 4
|
95
|
-
@
|
95
|
+
@klass.class_eval do
|
96
96
|
scope name, lambda { where(conditions) }
|
97
97
|
end
|
98
98
|
elsif ActiveRecord::VERSION::MAJOR >= 3
|
99
|
-
@
|
99
|
+
@klass.class_eval do
|
100
100
|
scope name, where(conditions)
|
101
101
|
end
|
102
102
|
else
|
103
|
-
@
|
103
|
+
@klass.class_eval do
|
104
104
|
named_scope name, :conditions => conditions
|
105
105
|
end
|
106
106
|
end
|
107
|
-
elsif @
|
108
|
-
scope_options = lambda { @
|
109
|
-
@
|
107
|
+
elsif @klass.ancestors.map {|klass| klass.to_s}.include?("Mongoid::Document")
|
108
|
+
scope_options = lambda { @klass.send(:where, {@klass.aasm_column.to_sym => name.to_s}) }
|
109
|
+
@klass.send(:scope, name, scope_options)
|
110
110
|
end
|
111
111
|
end
|
112
112
|
end
|
data/lib/aasm/state.rb
CHANGED
@@ -2,9 +2,9 @@ module AASM
|
|
2
2
|
class State
|
3
3
|
attr_reader :name, :options
|
4
4
|
|
5
|
-
def initialize(name,
|
5
|
+
def initialize(name, klass, options={})
|
6
6
|
@name = name
|
7
|
-
@
|
7
|
+
@klass = klass
|
8
8
|
update(options)
|
9
9
|
end
|
10
10
|
|
@@ -48,7 +48,7 @@ module AASM
|
|
48
48
|
end
|
49
49
|
|
50
50
|
def localized_name
|
51
|
-
AASM::Localizer.new.human_state_name(@
|
51
|
+
AASM::Localizer.new.human_state_name(@klass, self)
|
52
52
|
end
|
53
53
|
alias human_name localized_name
|
54
54
|
|
data/lib/aasm/state_machine.rb
CHANGED
@@ -2,20 +2,17 @@ module AASM
|
|
2
2
|
class StateMachine
|
3
3
|
|
4
4
|
# the following two methods provide the storage of all state machines
|
5
|
-
def self.[](
|
6
|
-
(@machines ||= {})[
|
5
|
+
def self.[](klass)
|
6
|
+
(@machines ||= {})[klass.to_s]
|
7
7
|
end
|
8
8
|
|
9
|
-
def self.[]=(
|
10
|
-
(@machines ||= {})[
|
9
|
+
def self.[]=(klass, machine)
|
10
|
+
(@machines ||= {})[klass.to_s] = machine
|
11
11
|
end
|
12
12
|
|
13
13
|
attr_accessor :states, :events, :initial_state, :config
|
14
|
-
attr_reader :name
|
15
14
|
|
16
|
-
|
17
|
-
def initialize(name)
|
18
|
-
@name = name
|
15
|
+
def initialize
|
19
16
|
@initial_state = nil
|
20
17
|
@states = []
|
21
18
|
@events = {}
|
@@ -29,8 +26,15 @@ module AASM
|
|
29
26
|
@events = @events.dup
|
30
27
|
end
|
31
28
|
|
32
|
-
def add_state(name,
|
33
|
-
|
29
|
+
def add_state(name, klass, options)
|
30
|
+
set_initial_state(name, options)
|
31
|
+
@states << AASM::State.new(name, klass, options) unless @states.include?(name)
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def set_initial_state(name, options)
|
37
|
+
@initial_state = name if options[:initial] || !initial_state
|
34
38
|
end
|
35
39
|
|
36
40
|
end # StateMachine
|
data/lib/aasm/version.rb
CHANGED
data/spec/unit/event_spec.rb
CHANGED
@@ -58,6 +58,23 @@ describe 'transition inspection' do
|
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
61
|
+
describe 'transition inspection without from' do
|
62
|
+
let(:event) do
|
63
|
+
AASM::Event.new(:run) do
|
64
|
+
transitions :to => :running
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'should support inspecting transitions from other states' do
|
69
|
+
expect(event.transitions_from_state(:sleeping).map(&:to)).to eq([:running])
|
70
|
+
expect(event.transitions_from_state?(:sleeping)).to be_true
|
71
|
+
|
72
|
+
expect(event.transitions_from_state(:cleaning).map(&:to)).to eq([:running])
|
73
|
+
expect(event.transitions_from_state?(:cleaning)).to be_true
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
|
61
78
|
describe 'firing an event' do
|
62
79
|
it 'should return nil if the transitions are empty' do
|
63
80
|
obj = double('object', :aasm => double('aasm', :current_state => 'open'))
|
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: 3.2.
|
4
|
+
version: 3.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Scott Barron
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2014-
|
14
|
+
date: 2014-06-14 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: rake
|
@@ -45,14 +45,14 @@ dependencies:
|
|
45
45
|
name: rspec
|
46
46
|
requirement: !ruby/object:Gem::Requirement
|
47
47
|
requirements:
|
48
|
-
- - "
|
48
|
+
- - "~>"
|
49
49
|
- !ruby/object:Gem::Version
|
50
50
|
version: '2.14'
|
51
51
|
type: :development
|
52
52
|
prerelease: false
|
53
53
|
version_requirements: !ruby/object:Gem::Requirement
|
54
54
|
requirements:
|
55
|
-
- - "
|
55
|
+
- - "~>"
|
56
56
|
- !ruby/object:Gem::Version
|
57
57
|
version: '2.14'
|
58
58
|
- !ruby/object:Gem::Dependency
|