statelogic 1.1 → 1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +8 -2
- data/README.rdoc +14 -7
- data/lib/statelogic/activerecord.rb +8 -7
- data/lib/statelogic.rb +1 -1
- data/test/fixtures/orders.yml +3 -2
- data/test/statelogic_test.rb +16 -5
- data/test/test_helper.rb +1 -1
- metadata +39 -22
- data/lib/omg-statelogic.rb +0 -1
data/CHANGELOG
CHANGED
@@ -1,8 +1,14 @@
|
|
1
|
+
1.2 - 2010-03-16
|
2
|
+
- for all defined states also adds named_scopes :"#{attr_name}_is_#{state_name}"
|
3
|
+
for example if state is :new, tries to add named_scope :new (it fails) and then
|
4
|
+
it adds :state_is_new so the named_scope for state :new is still accessible
|
5
|
+
[by Petr Chalupa (http://github.com/pitrch)]
|
6
|
+
|
1
7
|
1.1 - 2009-08-11
|
2
8
|
- adds finder methods in the form of find_all_#{state}(*args)
|
3
9
|
- adds named scope named after corresponding state
|
4
10
|
- no longer redefines existing methods with the same names, issues warnings instead
|
5
11
|
- forces state names to underscore notation when used as part of method/scope names
|
6
12
|
|
7
|
-
0.1.2 - 2009-01-10
|
8
|
-
- Support scoping arbitrary callbacks beyond ActiveRecord's
|
13
|
+
0.1.2 - 2009-01-10
|
14
|
+
- Support scoping arbitrary callbacks beyond ActiveRecord's
|
data/README.rdoc
CHANGED
@@ -12,6 +12,13 @@ consistency over merely formal... whatever...
|
|
12
12
|
- ???????
|
13
13
|
- PROFIT!!!11
|
14
14
|
|
15
|
+
=== Changes in v1.2
|
16
|
+
_Please review these carefully as they may be incompatible with your existing code._
|
17
|
+
- for all defined states also adds named_scopes :"#{attr_name}_is_#{state_name}"
|
18
|
+
for example if state is :new, tries to add named_scope :new (it fails) and then
|
19
|
+
it adds :state_is_new so the named_scope for state :new is still accessible
|
20
|
+
[by Petr Chalupa (http://github.com/pitrch)]
|
21
|
+
|
15
22
|
=== Changes in v1.1
|
16
23
|
_Please review these carefully as they may be incompatible with your existing code._
|
17
24
|
- adds finder methods in the form of +find_all_#{state}(*args)+ (Order.find_all_ready) sugg. by ares
|
@@ -20,7 +27,7 @@ _Please review these carefully as they may be incompatible with your existing co
|
|
20
27
|
- forces state names to underscore notation when used as part of method names
|
21
28
|
|
22
29
|
=== Installation
|
23
|
-
gem install
|
30
|
+
gem install statelogic
|
24
31
|
|
25
32
|
Installable as a plugin too.
|
26
33
|
|
@@ -39,7 +46,7 @@ Please report via Github issue tracking.
|
|
39
46
|
initial_state 'unpaid' do
|
40
47
|
transitions_to 'ready', 'suspended' # won't let you change to wrong states
|
41
48
|
end
|
42
|
-
state 'ready' do # you get +ready?+, +was_ready
|
49
|
+
state 'ready' do # you get +ready?+, +was_ready?+; +Order.ready+, +Order.state_is_ready+; named scopes and +Order.find_all_ready+ finder
|
43
50
|
transitions_to 'redeemed', 'suspended'
|
44
51
|
validates_presence_of :txref # scoped validations
|
45
52
|
before_save :prepare_for_plucking # scoped callbacks
|
@@ -69,13 +76,13 @@ Please report via Github issue tracking.
|
|
69
76
|
# for something more specific if it's to be displayed to user.
|
70
77
|
|
71
78
|
|
79
|
+
=== Contributors:
|
80
|
+
- Petr Chalupa (http://github.com/pitrch)
|
81
|
+
|
72
82
|
=== See also
|
73
83
|
* http://github.com/omg/threadpool -- Thread pool implementation
|
74
|
-
* http://github.com/omg/peanuts
|
75
|
-
|
76
|
-
|
77
|
-
Hint: If you feel like generous today you can tip me at http://tipjoy.com/u/pisuka
|
78
|
-
|
84
|
+
* http://github.com/omg/peanuts -- Ruby <-> XML mapping
|
85
|
+
* http://github.com/omg/slash -- HTTP/REST client
|
79
86
|
|
80
87
|
Copyright (c) 2009 Igor Gunko, released under the MIT license
|
81
88
|
|
@@ -14,7 +14,7 @@ module Statelogic
|
|
14
14
|
c = meta ? cls.metaclass : cls
|
15
15
|
unless c.method_defined?(name)
|
16
16
|
c.send(:define_method, name, &block)
|
17
|
-
|
17
|
+
debug { "Statelogic created #{meta ? 'class' : 'instance'} method #{name} on #{cls.name}." }
|
18
18
|
else
|
19
19
|
warn { "Statelogic won't override #{meta ? 'class' : 'instance'} method #{name} already defined on #{cls.name}." }
|
20
20
|
nil
|
@@ -81,15 +81,16 @@ module Statelogic
|
|
81
81
|
Util.defmethod(@class, "#{uname}?") { send(attr) == name }
|
82
82
|
Util.defmethod(@class, "was_#{uname}?") { send(attr_was) == name }
|
83
83
|
|
84
|
-
|
85
|
-
@class.
|
86
|
-
|
87
|
-
|
88
|
-
|
84
|
+
[uname, "#{attr}_is_#{uname}".to_sym].each do |named_scope_name|
|
85
|
+
unless @class.respond_to?(named_scope_name)
|
86
|
+
@class.send(:named_scope, named_scope_name, :conditions => {attr.to_sym => name })
|
87
|
+
Util.debug { "Statelogic has defined named scope #{named_scope_name} on #{@class.name}." }
|
88
|
+
else
|
89
|
+
Util.warn { "Statelogic won't override class method #{named_scope_name} already defined on #{@class.name}." }
|
90
|
+
end
|
89
91
|
end
|
90
92
|
|
91
93
|
Util.defmethod(@class, "find_all_#{uname}", true) {|*args| send(find_all_by_attr, name, *args) }
|
92
|
-
|
93
94
|
StateScopeHelper.new(@class, name, @config).instance_eval(&block) if block_given?
|
94
95
|
|
95
96
|
@config[:states] << name
|
data/lib/statelogic.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
# undisturbed void
|
1
|
+
# undisturbed void
|
data/test/fixtures/orders.yml
CHANGED
data/test/statelogic_test.rb
CHANGED
@@ -8,11 +8,12 @@ class OrderTest < ActiveSupport::TestCase
|
|
8
8
|
|
9
9
|
fixtures :orders
|
10
10
|
|
11
|
-
should_have_class_methods
|
12
|
-
should_have_class_methods :
|
11
|
+
should_have_class_methods :unpaid, :ready, :redeemed, :suspended
|
12
|
+
should_have_class_methods :state_is_new, :state_is_unpaid, :state_is_ready, :state_is_redeemed, :state_is_suspended
|
13
|
+
should_have_class_methods :find_all_new, :find_all_unpaid, :find_all_ready, :find_all_redeemed, :find_all_suspended
|
13
14
|
|
14
|
-
should_have_instance_methods :unpaid?, :ready?, :redeemed?, :suspended?
|
15
|
-
should_have_instance_methods :was_unpaid?, :was_ready?, :was_redeemed?, :was_suspended?
|
15
|
+
should_have_instance_methods :new?, :unpaid?, :ready?, :redeemed?, :suspended?
|
16
|
+
should_have_instance_methods :was_new?, :was_unpaid?, :was_ready?, :was_redeemed?, :was_suspended?
|
16
17
|
|
17
18
|
context 'Finders and scopes' do
|
18
19
|
should 'return adequate shit' do
|
@@ -28,12 +29,22 @@ class OrderTest < ActiveSupport::TestCase
|
|
28
29
|
context 'A fresh order' do
|
29
30
|
subject { Order.new }
|
30
31
|
|
31
|
-
should_allow_values_for :state, 'unpaid'
|
32
|
+
should_allow_values_for :state, 'unpaid', 'new'
|
32
33
|
should_not_allow_values_for :state, 'ready', 'redeemed', 'suspended', 'screwed_up',
|
33
34
|
:message => default_error_message(:inclusion)
|
34
35
|
should_not_require_attributes :txref, :redeemed_at, :facility_id
|
35
36
|
end
|
36
37
|
|
38
|
+
context 'A new order' do
|
39
|
+
subject { orders(:new) }
|
40
|
+
|
41
|
+
should_allow_values_for :state, 'redeemed', 'suspended'
|
42
|
+
should_not_allow_values_for :state, 'ready', 'screwed_up',
|
43
|
+
:message => default_error_message(:inclusion)
|
44
|
+
should_validate_presence_of :txref
|
45
|
+
should_not_require_attributes :redeemed_at, :facility_id
|
46
|
+
end
|
47
|
+
|
37
48
|
context 'An unpaid order' do
|
38
49
|
subject { orders(:unpaid) }
|
39
50
|
|
data/test/test_helper.rb
CHANGED
@@ -12,7 +12,7 @@ require 'shoulda_macros/statelogic'
|
|
12
12
|
#ActiveRecord::TestFixtures.fixture_path = 'test/fixtures'
|
13
13
|
|
14
14
|
ActiveRecord::Base.configurations = {
|
15
|
-
'test' => {:adapter => 'sqlite3', :
|
15
|
+
'test' => {:adapter => 'sqlite3', :database => ':memory:'}
|
16
16
|
}
|
17
17
|
ActiveRecord::Base.establish_connection(:test)
|
18
18
|
|
metadata
CHANGED
@@ -1,7 +1,11 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: statelogic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 1
|
7
|
+
- 2
|
8
|
+
version: "1.2"
|
5
9
|
platform: ruby
|
6
10
|
authors:
|
7
11
|
- Igor Gunko
|
@@ -9,39 +13,51 @@ autorequire:
|
|
9
13
|
bindir: bin
|
10
14
|
cert_chain: []
|
11
15
|
|
12
|
-
date:
|
16
|
+
date: 2010-03-16 00:00:00 +02:00
|
13
17
|
default_executable:
|
14
18
|
dependencies:
|
15
19
|
- !ruby/object:Gem::Dependency
|
16
20
|
name: activerecord
|
17
|
-
|
18
|
-
|
19
|
-
version_requirements: !ruby/object:Gem::Requirement
|
21
|
+
prerelease: false
|
22
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
23
|
requirements:
|
21
24
|
- - ">="
|
22
25
|
- !ruby/object:Gem::Version
|
26
|
+
segments:
|
27
|
+
- 2
|
28
|
+
- 3
|
29
|
+
- 2
|
23
30
|
version: 2.3.2
|
24
|
-
|
31
|
+
type: :runtime
|
32
|
+
version_requirements: *id001
|
25
33
|
- !ruby/object:Gem::Dependency
|
26
|
-
name:
|
27
|
-
|
28
|
-
|
29
|
-
version_requirements: !ruby/object:Gem::Requirement
|
34
|
+
name: shoulda
|
35
|
+
prerelease: false
|
36
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
30
37
|
requirements:
|
31
|
-
- -
|
38
|
+
- - ~>
|
32
39
|
- !ruby/object:Gem::Version
|
33
|
-
|
34
|
-
|
40
|
+
segments:
|
41
|
+
- 2
|
42
|
+
- 10
|
43
|
+
- 3
|
44
|
+
version: 2.10.3
|
45
|
+
type: :development
|
46
|
+
version_requirements: *id002
|
35
47
|
- !ruby/object:Gem::Dependency
|
36
48
|
name: sqlite3-ruby
|
37
|
-
|
38
|
-
|
39
|
-
version_requirements: !ruby/object:Gem::Requirement
|
49
|
+
prerelease: false
|
50
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
40
51
|
requirements:
|
41
52
|
- - ">="
|
42
53
|
- !ruby/object:Gem::Version
|
43
|
-
|
44
|
-
|
54
|
+
segments:
|
55
|
+
- 1
|
56
|
+
- 2
|
57
|
+
- 5
|
58
|
+
version: 1.2.5
|
59
|
+
type: :development
|
60
|
+
version_requirements: *id003
|
45
61
|
description: " Statelogic does kinda this and that... you know.\n"
|
46
62
|
email: tekmon@gmail.com
|
47
63
|
executables: []
|
@@ -58,7 +74,6 @@ files:
|
|
58
74
|
- MIT-LICENSE
|
59
75
|
- Rakefile
|
60
76
|
- lib/statelogic.rb
|
61
|
-
- lib/omg-statelogic.rb
|
62
77
|
- lib/statelogic/activerecord.rb
|
63
78
|
- lib/statelogic/callbacks_ext.rb
|
64
79
|
- rails/init.rb
|
@@ -77,18 +92,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
77
92
|
requirements:
|
78
93
|
- - ">="
|
79
94
|
- !ruby/object:Gem::Version
|
95
|
+
segments:
|
96
|
+
- 0
|
80
97
|
version: "0"
|
81
|
-
version:
|
82
98
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
99
|
requirements:
|
84
100
|
- - ">="
|
85
101
|
- !ruby/object:Gem::Version
|
102
|
+
segments:
|
103
|
+
- 0
|
86
104
|
version: "0"
|
87
|
-
version:
|
88
105
|
requirements: []
|
89
106
|
|
90
107
|
rubyforge_project:
|
91
|
-
rubygems_version: 1.3.
|
108
|
+
rubygems_version: 1.3.6
|
92
109
|
signing_key:
|
93
110
|
specification_version: 2
|
94
111
|
summary: Another state machine for ActiveRecord
|
data/lib/omg-statelogic.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
require 'statelogic'
|