acts_as_versioned 0.2 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +4 -0
- data/lib/acts_as_versioned.rb +10 -7
- data/test/fixtures/activerecord_versioned.sqlite +0 -0
- metadata +1 -1
data/CHANGELOG
CHANGED
data/lib/acts_as_versioned.rb
CHANGED
@@ -137,7 +137,7 @@ module ActiveRecord #:nodoc:
|
|
137
137
|
options[:if_changed] = [options[:if_changed]] unless options[:if_changed].is_a?(Array)
|
138
138
|
options[:if_changed].each do |attr_name|
|
139
139
|
define_method("#{attr_name}=") do |value|
|
140
|
-
(self.changed_attributes ||= []) << attr_name.to_s unless self.
|
140
|
+
(self.changed_attributes ||= []) << attr_name.to_s unless self.changed?(attr_name) or self.send(attr_name) == value
|
141
141
|
write_attribute(attr_name.to_s, value)
|
142
142
|
end
|
143
143
|
end
|
@@ -234,14 +234,17 @@ module ActiveRecord #:nodoc:
|
|
234
234
|
self.attributes.keys.select { |k| !self.class.non_versioned_fields.include?(k) }
|
235
235
|
end
|
236
236
|
|
237
|
-
# If called with no parameters, gets whether the current model
|
238
|
-
# If called with a single parameter, gets whether the parameter
|
239
|
-
def
|
237
|
+
# If called with no parameters, gets whether the current model has changed and needs to be versioned.
|
238
|
+
# If called with a single parameter, gets whether the parameter has changed.
|
239
|
+
def changed?(attr_name = nil)
|
240
240
|
attr_name.nil? ?
|
241
241
|
(!self.class.track_changed_attributes or (changed_attributes and changed_attributes.length > 0)) :
|
242
242
|
(changed_attributes and changed_attributes.include?(attr_name.to_s))
|
243
243
|
end
|
244
244
|
|
245
|
+
# keep old dirty? method
|
246
|
+
alias_method :dirty?, :changed?
|
247
|
+
|
245
248
|
# Clones a model. Used when saving a new version or reverting a model's version.
|
246
249
|
def clone_versioned_model(orig_model, new_model)
|
247
250
|
self.versioned_attributes.each do |key|
|
@@ -255,9 +258,9 @@ module ActiveRecord #:nodoc:
|
|
255
258
|
end
|
256
259
|
end
|
257
260
|
|
258
|
-
# Checks whether a new version shall be saved or not. Calls <tt>version_condition_met?</tt> and <tt>
|
261
|
+
# Checks whether a new version shall be saved or not. Calls <tt>version_condition_met?</tt> and <tt>changed?</tt>.
|
259
262
|
def save_version?
|
260
|
-
version_condition_met? and
|
263
|
+
version_condition_met? and changed?
|
261
264
|
end
|
262
265
|
|
263
266
|
# 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:
|
|
285
288
|
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
|
286
289
|
end
|
287
290
|
|
288
|
-
# clears current
|
291
|
+
# clears current changed attributes. Called after save.
|
289
292
|
def clear_changed_attributes
|
290
293
|
self.changed_attributes = []
|
291
294
|
end
|
Binary file
|