Skip to content

Commit

Permalink
forgot to checkin, renamed dirty? to changed?
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.techno-weenie.net/projects/acts_as_versioned@104 567b1171-46fb-0310-a4c9-b4bef9110e78
  • Loading branch information
technoweenie committed Oct 10, 2005
1 parent 25d9f68 commit df1d28b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
17 changes: 10 additions & 7 deletions lib/acts_as_versioned.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def acts_as_versioned(options = {})
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
Expand Down Expand Up @@ -234,14 +234,17 @@ def versioned_attributes
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|
Expand All @@ -255,9 +258,9 @@ def clone_versioned_model(orig_model, new_model)
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
Expand Down Expand Up @@ -285,7 +288,7 @@ def next_version
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
Expand Down

0 comments on commit df1d28b

Please sign in to comment.