public
Rubygem
Description: AASM - State machines for Ruby classes
Homepage: http://rubyi.st/aasm
Clone URL: git://github.com/rubyist/aasm.git
Click here to lend your support to: aasm and make a donation at www.pledgie.com !
Merge in Jan De Poorter's [DefV] named_scope addition to AR persistence layer, 
with some organizational clean up.
rubyist (author)
Fri May 30 14:23:23 -0700 2008
commit  83bbe4d082b40d7fb7334c7fc5efd3bfe9d64ffb
tree    014c0ceab66306b08eaec58b756206c6940da456
parent  270d9e12440f66f48f01e7f5ac16d4874a6980fd
...
 
 
1
 
2
 
3
4
5
...
1
2
3
4
5
6
7
8
9
0
@@ -1,5 +1,9 @@
0
+* Use named_scope in AR persistence layer, if available [Jan De Poorter]
0
+
0
 * Incremented version number
0
+
0
 * Cleaned up aasm_states_for_select to return the value as a string
0
+
0
 * Specs and bug fixes for the ActiveRecordPersistence, keeping persistence columns in sync
0
   Allowing for nil values in states for active record
0
   Only set state to default state before_validation_on_create
...
36
37
38
39
 
 
 
 
 
 
 
 
 
 
 
 
 
40
41
42
...
211
212
213
 
 
 
 
 
 
 
214
215
216
...
36
37
38
 
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
...
223
224
225
226
227
228
229
230
231
232
233
234
235
0
@@ -36,7 +36,19 @@ module AASM
0
         base.send(:include, AASM::Persistence::ActiveRecordPersistence::InstanceMethods)
0
         base.send(:include, AASM::Persistence::ActiveRecordPersistence::ReadState) unless base.method_defined?(:aasm_read_state)
0
         base.send(:include, AASM::Persistence::ActiveRecordPersistence::WriteState) unless base.method_defined?(:aasm_write_state)
0
-        base.send(:include, AASM::Persistence::ActiveRecordPersistence::WriteStateWithoutPersistence) unless base.method_defined?(:aasm_write_state_without_persistence)        
0
+        base.send(:include, AASM::Persistence::ActiveRecordPersistence::WriteStateWithoutPersistence) unless base.method_defined?(:aasm_write_state_without_persistence)
0
+        
0
+        if base.respond_to?(:named_scope)
0
+          base.extend(AASM::Persistence::ActiveRecordPersistence::NamedScopeMethods)
0
+          
0
+          base.class_eval do
0
+            class << self
0
+              alias_method :aasm_state_without_named_scope, :aasm_state
0
+              alias_method :aasm_state, :aasm_state_with_named_scope
0
+            end
0
+          end
0
+        end
0
+        
0
         base.before_validation_on_create :aasm_ensure_initial_state
0
       end
0
 
0
@@ -211,6 +223,13 @@ module AASM
0
           end
0
         end
0
       end
0
+
0
+      module NamedScopeMethods
0
+        def aasm_state_with_named_scope name, options = {}
0
+          aasm_state_without_named_scope name, options
0
+          self.named_scope name, :conditions => {self.aasm_column => name.to_s} unless self.scopes.include?(name)
0
+        end       
0
+      end
0
     end
0
   end
0
 end

Comments