openhood-simple_state_machine 2.0.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -6,27 +6,30 @@ PATH
6
6
  GEM
7
7
  remote: http://rubygems.org/
8
8
  specs:
9
- activemodel (3.0.9)
10
- activesupport (= 3.0.9)
11
- builder (~> 2.1.2)
12
- i18n (~> 0.5.0)
13
- activerecord (3.0.9)
14
- activemodel (= 3.0.9)
15
- activesupport (= 3.0.9)
16
- arel (~> 2.0.10)
17
- tzinfo (~> 0.3.23)
18
- activesupport (3.0.9)
19
- arel (2.0.10)
9
+ activemodel (3.1.1)
10
+ activesupport (= 3.1.1)
11
+ builder (~> 3.0.0)
12
+ i18n (~> 0.6)
13
+ activerecord (3.1.1)
14
+ activemodel (= 3.1.1)
15
+ activesupport (= 3.1.1)
16
+ arel (~> 2.2.1)
17
+ tzinfo (~> 0.3.29)
18
+ activesupport (3.1.1)
19
+ multi_json (~> 1.0)
20
+ arel (2.2.1)
20
21
  bson (1.3.1)
21
- builder (2.1.2)
22
+ bson_ext (1.3.1)
23
+ builder (3.0.0)
22
24
  diff-lcs (1.1.2)
23
- i18n (0.5.0)
25
+ i18n (0.6.0)
24
26
  mongo (1.3.1)
25
27
  bson (>= 1.3.1)
26
28
  mongo_mapper (0.9.1)
27
29
  activemodel (~> 3.0)
28
30
  activesupport (~> 3.0)
29
31
  plucky (~> 0.3.8)
32
+ multi_json (1.0.3)
30
33
  plucky (0.3.8)
31
34
  mongo (~> 1.3)
32
35
  rake (0.8.7)
@@ -38,14 +41,15 @@ GEM
38
41
  rspec-expectations (2.6.0)
39
42
  diff-lcs (~> 1.1.2)
40
43
  rspec-mocks (2.6.0)
41
- sqlite3 (1.3.3)
42
- tzinfo (0.3.28)
44
+ sqlite3 (1.3.4)
45
+ tzinfo (0.3.30)
43
46
 
44
47
  PLATFORMS
45
48
  ruby
46
49
 
47
50
  DEPENDENCIES
48
51
  activerecord (>= 3.0.0)
52
+ bson_ext (~> 1.3.0)
49
53
  mongo_mapper (~> 0.9.0)
50
54
  openhood-simple_state_machine!
51
55
  rake (~> 0.8.7)
@@ -0,0 +1,71 @@
1
+ SimpleStateMachine
2
+ ==================
3
+
4
+ Allow an Active Record or MongoMapper model to act as a finite state machine just as the popular plugin acts_as_state_machine but with many enhancements such as the possibility to have multiple states per object.
5
+
6
+ It can work together with the classic act_as_state_machine on the same project but both cannot be used at the same time for one given Active Record model. Moreover, simple_state_machine work standalone and doesn't require acts_as_state_machine.
7
+
8
+ You also get magic methods to check current state and a way to revert to previous state in database (or initial value for a new record) if something went wrong.
9
+
10
+
11
+ Dependencies
12
+ ------------
13
+
14
+ * Ruby 1.8.7 or 1.9.2
15
+
16
+ Lazy dependencies
17
+ -----------------
18
+
19
+ * gem "active_record", ">= 3.0.0"
20
+ * gem "mongo_mapper", "~> 0.9.0"
21
+
22
+ Usage
23
+ -----
24
+
25
+ * With ActiveRecord
26
+
27
+ require "simple_state_machine/active_record"
28
+
29
+ class Chicken < ActiveRecord::Base
30
+ state_machine :user_state, [:pending, :active, :removed, :on_hold]
31
+ state_machine :validation_state, [:waiting, :reviewed, :validated, :invalid]
32
+ def user_activate!
33
+ return false if !user_state_pending?
34
+ self.user_state = :active
35
+ save! rescue user_state_revert
36
+ user_state_active?
37
+ end
38
+ end
39
+
40
+ # And then you can do:
41
+
42
+ c = Chicken.create # c.user_state = :pending
43
+ c.user_activate! # c.user_state = :active
44
+
45
+ * With MongoMapper
46
+
47
+ require "simple_state_machine/mongo_mapper"
48
+
49
+ class Chicken
50
+ include MongoMapper::Document
51
+ plugin SimpleStateMachine::MongoMapper
52
+
53
+ state_machine :user_state, [:pending, :active, :removed, :on_hold]
54
+ state_machine :validation_state, [:waiting, :reviewed, :validated, :invalid]
55
+ def user_activate!
56
+ return false if !user_state_pending?
57
+ self.user_state = :active
58
+ save! rescue user_state_revert
59
+ user_state_active?
60
+ end
61
+ end
62
+
63
+ # And then you can do:
64
+
65
+ c = Chicken.create # c.user_state = :pending
66
+ c.user_activate! # c.user_state = :active
67
+
68
+ License
69
+ -------
70
+
71
+ SimpleStateMachine is Copyright © 2010-2011 Openhood.com It is free software, and may be redistributed under the terms specified in the MIT-LICENSE file.
@@ -10,8 +10,8 @@ module SimpleStateMachine
10
10
 
11
11
  module ClassMethods
12
12
  def state_machine(column, states)
13
- create_empty_state_machine unless inheritable_attributes.key? :states
14
- inheritable_attributes[:states][column.to_sym] = states
13
+ create_empty_state_machine unless respond_to? :states
14
+ self.states[column.to_sym] = states
15
15
  validates_inclusion_of column, :in => states
16
16
  # should also override getter/setter to convert to strings
17
17
  self.class_eval <<-eos
@@ -40,9 +40,9 @@ module SimpleStateMachine
40
40
  private
41
41
 
42
42
  def create_empty_state_machine
43
- write_inheritable_attribute :states, {} # add a class variable
44
- class_inheritable_reader :states # make it read-only
45
-
43
+ class_attribute :states
44
+ self.states = {}
45
+
46
46
  after_initialize :set_initial_states
47
47
  self.class_eval do
48
48
  def set_initial_states
@@ -4,14 +4,14 @@ module SimpleStateMachine
4
4
 
5
5
  included do
6
6
  class_eval do
7
- write_inheritable_attribute :states, {}
8
- class_inheritable_reader :states
7
+ class_attribute :states
8
+ self.states = {}
9
9
  end
10
10
  end
11
11
 
12
12
  module ClassMethods
13
13
  def state_machine(column, column_states)
14
- inheritable_attributes[:states][column.to_sym] = column_states
14
+ states[column.to_sym] = column_states
15
15
 
16
16
  key column, String
17
17
  validates_inclusion_of column, :in => column_states
@@ -1,3 +1,3 @@
1
1
  module SimpleStateMachine
2
- VERSION = "2.0.0"
2
+ VERSION = "3.0.0"
3
3
  end
@@ -21,5 +21,6 @@ Gem::Specification.new do |s|
21
21
  s.add_development_dependency("rspec", ["~> 2.6.0"])
22
22
  s.add_development_dependency("sqlite3")
23
23
  s.add_development_dependency("activerecord", [">= 3.0.0"])
24
+ s.add_development_dependency("bson_ext", ["~> 1.3.0"])
24
25
  s.add_development_dependency("mongo_mapper", ["~> 0.9.0"])
25
26
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openhood-simple_state_machine
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 3.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,12 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2011-06-22 00:00:00.000000000 +02:00
14
- default_executable:
13
+ date: 2011-10-10 00:00:00.000000000Z
15
14
  dependencies:
16
15
  - !ruby/object:Gem::Dependency
17
16
  name: rake
18
- requirement: &2161201240 !ruby/object:Gem::Requirement
17
+ requirement: &2152903280 !ruby/object:Gem::Requirement
19
18
  none: false
20
19
  requirements:
21
20
  - - ~>
@@ -23,10 +22,10 @@ dependencies:
23
22
  version: 0.8.7
24
23
  type: :development
25
24
  prerelease: false
26
- version_requirements: *2161201240
25
+ version_requirements: *2152903280
27
26
  - !ruby/object:Gem::Dependency
28
27
  name: rspec
29
- requirement: &2161198760 !ruby/object:Gem::Requirement
28
+ requirement: &2152902760 !ruby/object:Gem::Requirement
30
29
  none: false
31
30
  requirements:
32
31
  - - ~>
@@ -34,10 +33,10 @@ dependencies:
34
33
  version: 2.6.0
35
34
  type: :development
36
35
  prerelease: false
37
- version_requirements: *2161198760
36
+ version_requirements: *2152902760
38
37
  - !ruby/object:Gem::Dependency
39
38
  name: sqlite3
40
- requirement: &2161197360 !ruby/object:Gem::Requirement
39
+ requirement: &2152902380 !ruby/object:Gem::Requirement
41
40
  none: false
42
41
  requirements:
43
42
  - - ! '>='
@@ -45,10 +44,10 @@ dependencies:
45
44
  version: '0'
46
45
  type: :development
47
46
  prerelease: false
48
- version_requirements: *2161197360
47
+ version_requirements: *2152902380
49
48
  - !ruby/object:Gem::Dependency
50
49
  name: activerecord
51
- requirement: &2161195840 !ruby/object:Gem::Requirement
50
+ requirement: &2152901820 !ruby/object:Gem::Requirement
52
51
  none: false
53
52
  requirements:
54
53
  - - ! '>='
@@ -56,10 +55,21 @@ dependencies:
56
55
  version: 3.0.0
57
56
  type: :development
58
57
  prerelease: false
59
- version_requirements: *2161195840
58
+ version_requirements: *2152901820
59
+ - !ruby/object:Gem::Dependency
60
+ name: bson_ext
61
+ requirement: &2152901300 !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ~>
65
+ - !ruby/object:Gem::Version
66
+ version: 1.3.0
67
+ type: :development
68
+ prerelease: false
69
+ version_requirements: *2152901300
60
70
  - !ruby/object:Gem::Dependency
61
71
  name: mongo_mapper
62
- requirement: &2161188280 !ruby/object:Gem::Requirement
72
+ requirement: &2152932540 !ruby/object:Gem::Requirement
63
73
  none: false
64
74
  requirements:
65
75
  - - ~>
@@ -67,7 +77,7 @@ dependencies:
67
77
  version: 0.9.0
68
78
  type: :development
69
79
  prerelease: false
70
- version_requirements: *2161188280
80
+ version_requirements: *2152932540
71
81
  description: Same as acts_as_state_machine but on multiple columns and with more strict
72
82
  validation, allow creation of complex events with parameters, used successfully
73
83
  on critical financial applications for quite a long time
@@ -80,7 +90,7 @@ files:
80
90
  - Gemfile
81
91
  - Gemfile.lock
82
92
  - MIT-LICENSE
83
- - README.textile
93
+ - README.md
84
94
  - Rakefile
85
95
  - init.rb
86
96
  - lib/simple_state_machine.rb
@@ -93,7 +103,6 @@ files:
93
103
  - spec/simple_state_machine/mongo_mapper_spec.rb
94
104
  - spec/spec_helper.rb
95
105
  - spec/support/mongo_mapper_helper.rb
96
- has_rdoc: true
97
106
  homepage: http://github.com/openhood/simple_state_machine
98
107
  licenses: []
99
108
  post_install_message:
@@ -114,7 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
114
123
  version: '0'
115
124
  requirements: []
116
125
  rubyforge_project:
117
- rubygems_version: 1.6.2
126
+ rubygems_version: 1.8.6
118
127
  signing_key:
119
128
  specification_version: 3
120
129
  summary: Same as acts_as_state_machine but on multiple columns and with more strict
@@ -1,50 +0,0 @@
1
- h2. State Machine
2
-
3
- Allow an Active Record or MongoMapper model to act as a finite state machine just as the popular plugin acts_as_state_machine but with many enhancements such as the possibility to have multiple states per object.
4
-
5
- It can work together with the classic act_as_state_machine on the same project but both cannot be used at the same time for one given Active Record model. Moreover, simple_state_machine work standalone and doesn't require acts_as_state_machine.
6
-
7
- You also get magic methods to check current state and a way to revert to previous state in database (or initial value for a new record) if something went wrong.
8
-
9
- h3. Example for ActiveRecord
10
-
11
- require "simple_state_machine/active_record"
12
-
13
- class Chicken < ActiveRecord::Base
14
- state_machine :user_state, [:pending, :active, :removed, :on_hold]
15
- state_machine :validation_state, [:waiting, :reviewed, :validated, :invalid]
16
- def user_activate!
17
- return false if !user_state_pending?
18
- self.user_state = :active
19
- save! rescue user_state_revert
20
- user_state_active?
21
- end
22
- end
23
-
24
- And then you can do:
25
-
26
- c = Chicken.create # c.user_state = :pending
27
- c.user_activate! # c.user_state = :active
28
-
29
- h3. Example for MongoMapper
30
-
31
- require "simple_state_machine/mongo_mapper"
32
-
33
- class Chicken
34
- include MongoMapper::Document
35
- plugin SimpleStateMachine::MongoMapper
36
-
37
- state_machine :user_state, [:pending, :active, :removed, :on_hold]
38
- state_machine :validation_state, [:waiting, :reviewed, :validated, :invalid]
39
- def user_activate!
40
- return false if !user_state_pending?
41
- self.user_state = :active
42
- save! rescue user_state_revert
43
- user_state_active?
44
- end
45
- end
46
-
47
- And then you can do:
48
-
49
- c = Chicken.create # c.user_state = :pending
50
- c.user_activate! # c.user_state = :active