diff options
| author | technoweenie <technoweenie@567b1171-46fb-0310-a4c9-b4bef9110e78> | 2005-10-10 06:22:22 +0000 |
|---|---|---|
| committer | technoweenie <technoweenie@567b1171-46fb-0310-a4c9-b4bef9110e78> | 2005-10-10 06:22:22 +0000 |
| commit | df1d28b4ed9800a47e6aa36282cacbc6d05b3122 (patch) | |
| tree | 6b0126084e9218c1de2b69e5b99ae4c983dcb76e | |
| parent | 25d9f68ef8e39eeacff971933714cd3638b3d40f (diff) | |
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
| -rw-r--r-- | CHANGELOG | 4 | ||||
| -rw-r--r-- | Rakefile | 2 | ||||
| -rw-r--r-- | lib/acts_as_versioned.rb | 17 |
3 files changed, 15 insertions, 8 deletions
@@ -1,3 +1,7 @@ +*0.2.1* + +* (6 Oct 2005) renamed dirty? to changed? to keep it uniform. it was aliased to keep it backwards compatible. + *0.2* * (6 Oct 2005) added find_versions and find_version class methods. @@ -9,7 +9,7 @@ require 'rake/testtask' require 'rake/contrib/rubyforgepublisher' PKG_NAME = 'acts_as_versioned' -PKG_VERSION = '0.2' +PKG_VERSION = '0.2.1' PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}" PROD_HOST = "technoweenie@bidwell.textdrive.com" RUBY_FORGE_PROJECT = 'ar-versioned' diff --git a/lib/acts_as_versioned.rb b/lib/acts_as_versioned.rb index 13cc3c281..1918e5fb4 100644 --- a/lib/acts_as_versioned.rb +++ b/lib/acts_as_versioned.rb @@ -137,7 +137,7 @@ module ActiveRecord #:nodoc: options[:if_changed] = [options[:if_changed]] unless options[:if_changed].is_a?(Array) options[:if_changed].each do |attr_name| define_method("#{attr_name}=") do |value| - (self.changed_attributes ||= []) << attr_name.to_s unless self.dirty?(attr_name) or self.send(attr_name) == value + (self.changed_attributes ||= []) << attr_name.to_s unless self.changed?(attr_name) or self.send(attr_name) == value write_attribute(attr_name.to_s, value) end end @@ -234,14 +234,17 @@ module ActiveRecord #:nodoc: self.attributes.keys.select { |k| !self.class.non_versioned_fields.include?(k) } end - # If called with no parameters, gets whether the current model is dirty and needs to be versioned. - # If called with a single parameter, gets whether the parameter is currently dirty. - def dirty?(attr_name = nil) + # If called with no parameters, gets whether the current model has changed and needs to be versioned. + # If called with a single parameter, gets whether the parameter has changed. + def changed?(attr_name = nil) attr_name.nil? ? (!self.class.track_changed_attributes or (changed_attributes and changed_attributes.length > 0)) : (changed_attributes and changed_attributes.include?(attr_name.to_s)) end + # keep old dirty? method + alias_method :dirty?, :changed? + # Clones a model. Used when saving a new version or reverting a model's version. def clone_versioned_model(orig_model, new_model) self.versioned_attributes.each do |key| @@ -255,9 +258,9 @@ module ActiveRecord #:nodoc: end end - # Checks whether a new version shall be saved or not. Calls <tt>version_condition_met?</tt> and <tt>dirty?</tt>. + # Checks whether a new version shall be saved or not. Calls <tt>version_condition_met?</tt> and <tt>changed?</tt>. def save_version? - version_condition_met? and dirty? + version_condition_met? and changed? end # Checks condition set in the :if option to check whether a revision should be created or not. Override this for @@ -285,7 +288,7 @@ module ActiveRecord #:nodoc: 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 end - # clears current dirty attributes. Called after save. + # clears current changed attributes. Called after save. def clear_changed_attributes self.changed_attributes = [] end |
