public
Rubygem
Description: AASM - State machines for Ruby classes
Homepage: http://rubyi.st/aasm
Clone URL: git://github.com/rubyist/aasm.git
Search Repo:
Click here to lend your support to: aasm and make a donation at www.pledgie.com !
Take state column for AR persistance out of class variables and add them 
to the
StateMachine object.
rubyist (author)
Sun Jun 22 08:17:12 -0700 2008
commit  3d69497ee33c6ea6ebe30296e03e9e07283eed96
tree    65041243e6de7483e5404ab94a630833222ab495
parent  2d87b4b3b1e35fbd47b6bec5374990afa197d9c0
...
8
9
10
 
 
 
11
12
13
...
8
9
10
11
12
13
14
15
16
0
@@ -8,6 +8,9 @@ module AASM
0
   end
0
   
0
   def self.included(base) #:nodoc:
0
+ # TODO - need to ensure that a machine is being created because
0
+ # AASM was either included or arrived at via inheritance. It
0
+ # cannot be both.
0
     base.extend AASM::ClassMethods
0
     AASM::Persistence.set_persistence(base)
0
     AASM::StateMachine[base] = AASM::StateMachine.new('')
...
79
80
81
82
 
 
83
84
 
 
85
86
 
 
87
88
89
...
79
80
81
 
82
83
84
 
85
86
87
 
88
89
90
91
92
0
@@ -79,11 +79,14 @@ module AASM
0
         # This method is both a getter and a setter
0
         def aasm_column(column_name=nil)
0
           if column_name
0
- @aasm_column = column_name.to_sym
0
+ AASM::StateMachine[self].config.column = column_name.to_sym
0
+ # @aasm_column = column_name.to_sym
0
           else
0
- @aasm_column ||= :aasm_state
0
+ AASM::StateMachine[self].config.column ||= :aasm_state
0
+ # @aasm_column ||= :aasm_state
0
           end
0
- @aasm_column
0
+ # @aasm_column
0
+ AASM::StateMachine[self].config.column
0
         end
0
 
0
         def find_in_state(number, state, *args)
...
 
 
1
2
3
...
9
10
11
12
 
13
14
15
...
17
18
19
 
20
21
22
...
1
2
3
4
5
...
11
12
13
 
14
15
16
17
...
19
20
21
22
23
24
25
0
@@ -1,3 +1,5 @@
0
+require 'ostruct'
0
+
0
 module AASM
0
   class StateMachine
0
     def self.[](*args)
0
@@ -9,7 +11,7 @@ module AASM
0
       (@machines ||= {})[args] = val
0
     end
0
     
0
- attr_accessor :states, :events, :initial_state
0
+ attr_accessor :states, :events, :initial_state, :config
0
     attr_reader :name
0
     
0
     def initialize(name)
0
@@ -17,6 +19,7 @@ module AASM
0
       @initial_state = nil
0
       @states = []
0
       @events = {}
0
+ @config = OpenStruct.new
0
     end
0
 
0
     def create_state(name, options)
...
1
2
3
4
5
...
 
 
1
2
3
0
@@ -1,5 +1,3 @@
0
-require File.join(File.dirname(__FILE__), 'conversation')
0
-
0
 describe Conversation, 'description' do
0
   it '.aasm_states should contain all of the states' do
0
     Conversation.aasm_states.should == [:needs_attention, :read, :closed, :awaiting_response, :junk]
...
43
44
45
 
 
 
 
 
 
 
 
46
47
48
...
178
179
180
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
181
182
183
...
43
44
45
46
47
48
49
50
51
52
53
54
55
56
...
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
0
@@ -43,6 +43,14 @@ begin
0
     include AASM
0
   end
0
 
0
+ class June < ActiveRecord::Base
0
+ include AASM
0
+ aasm_column :status
0
+ end
0
+
0
+ class Beaver < June
0
+ end
0
+
0
   describe "aasm model", :shared => true do
0
     it "should include AASM::Persistence::ActiveRecordPersistence" do
0
       @klass.included_modules.should be_include(AASM::Persistence::ActiveRecordPersistence)
0
@@ -178,6 +186,21 @@ begin
0
     
0
   end
0
 
0
+ describe 'Beavers' do
0
+ it "should have the same states as it's parent" do
0
+ Beaver.aasm_states.should == June.aasm_states
0
+ end
0
+
0
+ it "should have the same events as it's parent" do
0
+ Beaver.aasm_events.should == June.aasm_events
0
+ end
0
+
0
+ it "should have the same column as it's parent" do
0
+ Beaver.aasm_column.should == :status
0
+ end
0
+ end
0
+
0
+
0
   # TODO: figure out how to test ActiveRecord reload! without a database
0
 
0
 rescue LoadError => e

Comments

    No one has commented yet.