Extract method setup_paper_trail_options
This commit is contained in:
parent
1526620c33
commit
6364eb5d54
|
@ -1,19 +1,14 @@
|
|||
# Remove these configuration records
|
||||
# one by one as the offenses are removed from the code base.
|
||||
|
||||
# Offense count: 19
|
||||
Metrics/AbcSize:
|
||||
Max: 46 # Goal: 15
|
||||
Max: 43 # Goal: 15
|
||||
|
||||
# Offense count: 6
|
||||
Metrics/CyclomaticComplexity:
|
||||
Max: 13
|
||||
Max: 13 # Goal: 6
|
||||
|
||||
# Offense count: 2
|
||||
# Configuration parameters: CountComments.
|
||||
Metrics/ModuleLength:
|
||||
Max: 299
|
||||
|
||||
# Offense count: 6
|
||||
Metrics/PerceivedComplexity:
|
||||
Max: 16
|
||||
Max: 16 # Goal: 7
|
||||
|
|
|
@ -54,6 +54,7 @@ module PaperTrail
|
|||
# other models latest state (if the other model is paper trailed, this
|
||||
# option does nothing)
|
||||
#
|
||||
# @api public
|
||||
def has_paper_trail(options = {})
|
||||
options[:on] ||= [:create, :update, :destroy]
|
||||
|
||||
|
@ -102,6 +103,9 @@ module PaperTrail
|
|||
end
|
||||
end
|
||||
|
||||
# Installs callbacks, associations, "class attributes", and more.
|
||||
# For details of how "class attributes" work, see the activesupport docs.
|
||||
# @api private
|
||||
def setup_model_for_paper_trail(options = {})
|
||||
# Lazily include the instance methods so we don't clutter up
|
||||
# any more ActiveRecord models than we have to.
|
||||
|
@ -117,18 +121,7 @@ module PaperTrail
|
|||
class_attribute :version_class_name
|
||||
self.version_class_name = options[:class_name] || "PaperTrail::Version"
|
||||
|
||||
class_attribute :paper_trail_options
|
||||
|
||||
self.paper_trail_options = options.dup
|
||||
|
||||
[:ignore, :skip, :only].each do |k|
|
||||
paper_trail_options[k] = [paper_trail_options[k]].flatten.compact.map { |attr|
|
||||
attr.is_a?(Hash) ? attr.stringify_keys : attr.to_s
|
||||
}
|
||||
end
|
||||
|
||||
paper_trail_options[:meta] ||= {}
|
||||
paper_trail_options[:save_changes] = true if paper_trail_options[:save_changes].nil?
|
||||
setup_paper_trail_options(options)
|
||||
|
||||
class_attribute :versions_association_name
|
||||
self.versions_association_name = options[:versions] || :versions
|
||||
|
@ -153,6 +146,22 @@ module PaperTrail
|
|||
after_rollback :clear_rolled_back_versions
|
||||
end
|
||||
|
||||
# Given `options`, populates `paper_trail_options`.
|
||||
# @api private
|
||||
def setup_paper_trail_options(options)
|
||||
class_attribute :paper_trail_options
|
||||
self.paper_trail_options = options.dup
|
||||
[:ignore, :skip, :only].each do |k|
|
||||
paper_trail_options[k] = [paper_trail_options[k]].flatten.compact.map { |attr|
|
||||
attr.is_a?(Hash) ? attr.stringify_keys : attr.to_s
|
||||
}
|
||||
end
|
||||
paper_trail_options[:meta] ||= {}
|
||||
if paper_trail_options[:save_changes].nil?
|
||||
paper_trail_options[:save_changes] = true
|
||||
end
|
||||
end
|
||||
|
||||
def setup_callbacks_from_options(options_on = [])
|
||||
options_on.each do |option|
|
||||
send "paper_trail_on_#{option}"
|
||||
|
|
Loading…
Reference in New Issue