public
Description: ActiveRecord plugin for versioning your models.
Clone URL: git://github.com/technoweenie/acts_as_versioned.git
forgot to checkin, renamed dirty? to changed?

git-svn-id: http://svn.techno-weenie.net/projects/acts_as_versioned@104 
567b1171-46fb-0310-a4c9-b4bef9110e78
technoweenie (author)
Sun Oct 09 23:22:22 -0700 2005
commit  df1d28b4ed9800a47e6aa36282cacbc6d05b3122
tree    6b0126084e9218c1de2b69e5b99ae4c983dcb76e
parent  25d9f68ef8e39eeacff971933714cd3638b3d40f
...
 
 
 
 
1
2
3
...
1
2
3
4
5
6
7
0
@@ -1,3 +1,7 @@
0
+*0.2.1*
0
+
0
+* (6 Oct 2005) renamed dirty? to changed? to keep it uniform. it was aliased to keep it backwards compatible.
0
+
0
 *0.2*
0
 
0
 * (6 Oct 2005) added find_versions and find_version class methods.
...
9
10
11
12
 
13
14
15
...
9
10
11
 
12
13
14
15
0
@@ -9,7 +9,7 @@ require 'rake/testtask'
0
 require 'rake/contrib/rubyforgepublisher'
0
 
0
 PKG_NAME = 'acts_as_versioned'
0
-PKG_VERSION = '0.2'
0
+PKG_VERSION = '0.2.1'
0
 PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
0
 PROD_HOST = "technoweenie@bidwell.textdrive.com"
0
 RUBY_FORGE_PROJECT = 'ar-versioned'
...
137
138
139
140
 
141
142
143
...
234
235
236
237
238
239
 
 
 
240
241
242
243
244
 
 
 
245
246
247
...
255
256
257
258
 
259
260
 
261
262
263
...
285
286
287
288
 
289
290
291
...
137
138
139
 
140
141
142
143
...
234
235
236
 
 
 
237
238
239
240
241
242
243
244
245
246
247
248
249
250
...
258
259
260
 
261
262
 
263
264
265
266
...
288
289
290
 
291
292
293
294
0
@@ -137,7 +137,7 @@ module ActiveRecord #:nodoc:
0
               options[:if_changed] = [options[:if_changed]] unless options[:if_changed].is_a?(Array)
0
               options[:if_changed].each do |attr_name|
0
                 define_method("#{attr_name}=") do |value|
0
- (self.changed_attributes ||= []) << attr_name.to_s unless self.dirty?(attr_name) or self.send(attr_name) == value
0
+ (self.changed_attributes ||= []) << attr_name.to_s unless self.changed?(attr_name) or self.send(attr_name) == value
0
                   write_attribute(attr_name.to_s, value)
0
                 end
0
               end
0
@@ -234,14 +234,17 @@ module ActiveRecord #:nodoc:
0
           self.attributes.keys.select { |k| !self.class.non_versioned_fields.include?(k) }
0
         end
0
         
0
- # If called with no parameters, gets whether the current model is dirty and needs to be versioned.
0
- # If called with a single parameter, gets whether the parameter is currently dirty.
0
- def dirty?(attr_name = nil)
0
+ # If called with no parameters, gets whether the current model has changed and needs to be versioned.
0
+ # If called with a single parameter, gets whether the parameter has changed.
0
+ def changed?(attr_name = nil)
0
           attr_name.nil? ?
0
             (!self.class.track_changed_attributes or (changed_attributes and changed_attributes.length > 0)) :
0
             (changed_attributes and changed_attributes.include?(attr_name.to_s))
0
         end
0
         
0
+ # keep old dirty? method
0
+ alias_method :dirty?, :changed?
0
+
0
         # Clones a model. Used when saving a new version or reverting a model's version.
0
         def clone_versioned_model(orig_model, new_model)
0
           self.versioned_attributes.each do |key|
0
@@ -255,9 +258,9 @@ module ActiveRecord #:nodoc:
0
           end
0
         end
0
         
0
- # Checks whether a new version shall be saved or not. Calls <tt>version_condition_met?</tt> and <tt>dirty?</tt>.
0
+ # Checks whether a new version shall be saved or not. Calls <tt>version_condition_met?</tt> and <tt>changed?</tt>.
0
         def save_version?
0
- version_condition_met? and dirty?
0
+ version_condition_met? and changed?
0
         end
0
         
0
         # Checks condition set in the :if option to check whether a revision should be created or not. Override this for
0
@@ -285,7 +288,7 @@ module ActiveRecord #:nodoc:
0
           connection.select_one("SELECT MAX(version)+1 AS next_version FROM #{self.class.versioned_table_name} WHERE #{self.class.versioned_foreign_key} = #{self.id}")['next_version'] || 1
0
         end
0
         
0
- # clears current dirty attributes. Called after save.
0
+ # clears current changed attributes. Called after save.
0
         def clear_changed_attributes
0
           self.changed_attributes = []
0
         end

Comments

    No one has commented yet.