mirror of
https://github.com/paper-trail-gem/paper_trail.git
synced 2022-11-09 11:33:19 -05:00
Replaced the class attributes used to keep options by a single paper_trail_options
attribute which should reduce the risk of name clashes with existing code base or other gems.
This commit is contained in:
parent
e870e0d561
commit
cbb07a89be
1 changed files with 16 additions and 16 deletions
|
@ -44,20 +44,15 @@ module PaperTrail
|
||||||
class_attribute :ignore
|
class_attribute :ignore
|
||||||
self.ignore = ([options[:ignore]].flatten.compact || []).map &:to_s
|
self.ignore = ([options[:ignore]].flatten.compact || []).map &:to_s
|
||||||
|
|
||||||
class_attribute :if_condition
|
class_attribute :paper_trail_options
|
||||||
self.if_condition = options[:if]
|
self.paper_trail_options = options.dup
|
||||||
|
|
||||||
class_attribute :unless_condition
|
%w(ignore skip only).map(&:to_sym).each do |k|
|
||||||
self.unless_condition = options[:unless]
|
paper_trail_options[k] =
|
||||||
|
([paper_trail_options[k]].flatten.compact || []).map &:to_s
|
||||||
|
end
|
||||||
|
|
||||||
class_attribute :skip
|
paper_trail_options[:meta] ||= {}
|
||||||
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
|
||||||
|
@ -183,7 +178,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)
|
||||||
|
@ -210,7 +205,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?
|
||||||
|
@ -218,11 +213,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?
|
||||||
|
@ -230,6 +228,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