mirror of
https://github.com/paper-trail-gem/paper_trail.git
synced 2022-11-09 11:33:19 -05:00
Merge remote-tracking branch 'budu/master'
This commit is contained in:
commit
1bf2a03131
1 changed files with 16 additions and 19 deletions
|
@ -41,23 +41,15 @@ module PaperTrail
|
||||||
class_attribute :version_class_name
|
class_attribute :version_class_name
|
||||||
self.version_class_name = options[:class_name] || 'Version'
|
self.version_class_name = options[:class_name] || 'Version'
|
||||||
|
|
||||||
class_attribute :ignore
|
class_attribute :paper_trail_options
|
||||||
self.ignore = ([options[:ignore]].flatten.compact || []).map &:to_s
|
self.paper_trail_options = options.dup
|
||||||
|
|
||||||
class_attribute :if_condition
|
[:ignore, :skip, :only].each do |k|
|
||||||
self.if_condition = options[:if]
|
paper_trail_options[k] =
|
||||||
|
([paper_trail_options[k]].flatten.compact || []).map &:to_s
|
||||||
|
end
|
||||||
|
|
||||||
class_attribute :unless_condition
|
paper_trail_options[:meta] ||= {}
|
||||||
self.unless_condition = options[:unless]
|
|
||||||
|
|
||||||
class_attribute :skip
|
|
||||||
self.skip = ([options[:skip]].flatten.compact || []).map &:to_s
|
|
||||||
|
|
||||||
class_attribute :only
|
|
||||||
self.only = ([options[:only]].flatten.compact || []).map &:to_s
|
|
||||||
|
|
||||||
class_attribute :meta
|
|
||||||
self.meta = options[:meta] || {}
|
|
||||||
|
|
||||||
class_attribute :paper_trail_enabled_for_model
|
class_attribute :paper_trail_enabled_for_model
|
||||||
self.paper_trail_enabled_for_model = true
|
self.paper_trail_enabled_for_model = true
|
||||||
|
@ -197,7 +189,7 @@ module PaperTrail
|
||||||
|
|
||||||
def merge_metadata(data)
|
def merge_metadata(data)
|
||||||
# First we merge the model-level metadata in `meta`.
|
# First we merge the model-level metadata in `meta`.
|
||||||
meta.each do |k,v|
|
paper_trail_options[:meta].each do |k,v|
|
||||||
data[k] =
|
data[k] =
|
||||||
if v.respond_to?(:call)
|
if v.respond_to?(:call)
|
||||||
v.call(self)
|
v.call(self)
|
||||||
|
@ -229,7 +221,7 @@ module PaperTrail
|
||||||
end
|
end
|
||||||
|
|
||||||
def object_to_string(object)
|
def object_to_string(object)
|
||||||
object.attributes.except(*self.class.skip).to_yaml
|
object.attributes.except(*self.class.paper_trail_options[:skip]).to_yaml
|
||||||
end
|
end
|
||||||
|
|
||||||
def changed_notably?
|
def changed_notably?
|
||||||
|
@ -237,11 +229,14 @@ module PaperTrail
|
||||||
end
|
end
|
||||||
|
|
||||||
def notably_changed
|
def notably_changed
|
||||||
self.class.only.empty? ? changed_and_not_ignored : (changed_and_not_ignored & self.class.only)
|
only = self.class.paper_trail_options[:only]
|
||||||
|
only.empty? ? changed_and_not_ignored : (changed_and_not_ignored & only)
|
||||||
end
|
end
|
||||||
|
|
||||||
def changed_and_not_ignored
|
def changed_and_not_ignored
|
||||||
changed - self.class.ignore - self.class.skip
|
ignore = self.class.paper_trail_options[:ignore]
|
||||||
|
skip = self.class.paper_trail_options[:skip]
|
||||||
|
changed - ignore - skip
|
||||||
end
|
end
|
||||||
|
|
||||||
def switched_on?
|
def switched_on?
|
||||||
|
@ -249,6 +244,8 @@ module PaperTrail
|
||||||
end
|
end
|
||||||
|
|
||||||
def save_version?
|
def save_version?
|
||||||
|
if_condition = self.class.paper_trail_options[:if]
|
||||||
|
unless_condition = self.class.paper_trail_options[:unless]
|
||||||
(if_condition.blank? || if_condition.call(self)) && !unless_condition.try(:call, self)
|
(if_condition.blank? || if_condition.call(self)) && !unless_condition.try(:call, self)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue