public
Description: Dirty ActiveRecord Versioning (update of acts_as_versioned)
Homepage: http://tuples.us/2008/05/03/lazily-announcing-version_fu/
Clone URL: git://github.com/jmckible/version_fu.git
Search Repo:
Remove method_missing functionality.
jmckible (author)
Tue Jul 08 13:56:06 -0700 2008
commit  a380b4c0edd7d494e5b0ec19ac508e960d35fca3
tree    a131c73da4fce154d8903c480e4c3879d80d92e5
parent  7cf1cab81f638988d2f7e33df91d6857dfabdff0
...
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
...
86
87
88
 
 
 
 
 
 
 
 
 
 
 
 
 
89
90
91
0
@@ -86,19 +86,6 @@ Now that you've got some versions, it would be nice to use ActiveRecord associat
0
 
0
 Don't forget the class name, or you'll get a warning
0
 
0
-
0
-== Method Missing
0
-
0
-If you call a method on a version and it's undefined, it'll be sent to the parent. For example, pages could have a creator attribute that doesn't change and is therefore unversioned. You don't need to define a creator method in the version_fu block.
0
-
0
- class Page < ActiveRecord::Base
0
- version_fu
0
- belongs_to :creator
0
- end
0
-
0
-Calling Pages.first.versions.latest.creator will be the same as calling Pages.first.creator.
0
-
0
-
0
 == When to Version
0
 
0
 By default a new version will be saved whenever a versioned column is changed. However, you can control this at a more fine grained level. Just override the create_new_version? method. For example, let's say you only want to save a new version if both the page title and body changed. Taking advantage of the dirty attribute methods, you could do something like this:
...
51
52
53
54
55
56
57
58
59
60
61
...
51
52
53
 
 
 
 
 
54
55
56
0
@@ -51,11 +51,6 @@ module VersionFu
0
         def next
0
           self.class.after(self)
0
         end
0
-
0
- # Pass any unknown methods to the parent object
0
- def method_missing(method, *args)
0
- eval(original_class.to_s.demodulize.underscore).__send__ method, *args
0
- end
0
       end
0
 
0
       # Housekeeping on versioned class
...
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
...
137
138
139
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
140
141
0
@@ -137,22 +137,4 @@ class VersionFuTest < Test::Unit::TestCase
0
   def test_should_take_a_block_containing_ar_extention
0
     assert_equal authors(:larry), page_versions(:welcome_1).author
0
   end
0
-
0
- #############################################################################
0
- # M E T H O D M I S S I N G #
0
- #############################################################################
0
- def test_should_send_missing_associations_to_parent_object
0
- assert_equal authors(:larry), page_versions(:welcome_1).creator
0
- end
0
-
0
- def test_should_send_regular_missing_methods_to_parent_object
0
- assert_equal "Hello World 1", author_versions(:sara_1).hello_world
0
- assert_equal "Hello World 2", author_versions(:sara_1).hello_world(2) # Test passing params
0
- end
0
-
0
- def test_should_eval_missing_methods_from_parent_in_versioned_class_binding
0
- # TODO Should probably be "Sara Maiden"
0
- assert_equal "Sara Smiles", author_versions(:sara_1).name
0
- end
0
-
0
 end
0
\ No newline at end of file

Comments

    No one has commented yet.