Code style: Break long lines
This commit is contained in:
parent
78f0983e76
commit
3a72b7f7c7
18
.rubocop.yml
18
.rubocop.yml
|
@ -13,3 +13,21 @@ AllCops:
|
|||
DisplayCopNames: true
|
||||
DisplayStyleGuide: true
|
||||
StyleGuideCopsOnly: false
|
||||
|
||||
Style/AlignParameters:
|
||||
EnforcedStyle: with_fixed_indentation
|
||||
|
||||
Style/DotPosition:
|
||||
EnforcedStyle: trailing
|
||||
|
||||
# The Ruby Style Guide says:
|
||||
#
|
||||
# > Use \ instead of + or << to concatenate two string literals at line end.
|
||||
#
|
||||
# but in my experience the `\` style is rarely used and less readable. Please
|
||||
# concatenate multiline strings with `+` or use a HEREDOC.
|
||||
Style/LineEndConcatenation:
|
||||
Enabled: false
|
||||
|
||||
Metrics/LineLength:
|
||||
Max: 100
|
||||
|
|
|
@ -46,20 +46,13 @@ Metrics/BlockNesting:
|
|||
Metrics/CyclomaticComplexity:
|
||||
Max: 14
|
||||
|
||||
# Offense count: 98
|
||||
# Configuration parameters: AllowURI, URISchemes.
|
||||
Metrics/LineLength:
|
||||
Max: 147
|
||||
|
||||
# Offense count: 15
|
||||
# Configuration parameters: CountComments.
|
||||
Metrics/MethodLength:
|
||||
Max: 51
|
||||
|
||||
# Offense count: 3
|
||||
# Configuration parameters: CountComments.
|
||||
Metrics/ModuleLength:
|
||||
Max: 257
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 7
|
||||
Metrics/PerceivedComplexity:
|
||||
|
@ -83,14 +76,6 @@ Style/AlignHash:
|
|||
Exclude:
|
||||
- 'lib/generators/paper_trail/install_generator.rb'
|
||||
|
||||
# Offense count: 4
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
||||
Style/AlignParameters:
|
||||
Exclude:
|
||||
- 'doc/bug_report_template.rb'
|
||||
- 'lib/paper_trail/has_paper_trail.rb'
|
||||
|
||||
# Offense count: 1
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
||||
|
@ -131,12 +116,6 @@ Style/DeprecatedHashMethods:
|
|||
Style/Documentation:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 31
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
||||
Style/DotPosition:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 5
|
||||
Style/DoubleNegation:
|
||||
Exclude:
|
||||
|
@ -232,13 +211,6 @@ Style/Lambda:
|
|||
- 'lib/paper_trail/has_paper_trail.rb'
|
||||
- 'lib/paper_trail/version_concern.rb'
|
||||
|
||||
# Offense count: 3
|
||||
# Cop supports --auto-correct.
|
||||
Style/LineEndConcatenation:
|
||||
Exclude:
|
||||
- 'lib/generators/paper_trail/install_generator.rb'
|
||||
- 'lib/paper_trail/config.rb'
|
||||
|
||||
# Offense count: 1
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
||||
|
|
|
@ -6,12 +6,15 @@ class CreateVersionAssociations < ActiveRecord::Migration
|
|||
t.integer :foreign_key_id
|
||||
end
|
||||
add_index :version_associations, [:version_id]
|
||||
add_index :version_associations, [:foreign_key_name, :foreign_key_id], :name => 'index_version_associations_on_foreign_key'
|
||||
add_index :version_associations,
|
||||
[:foreign_key_name, :foreign_key_id],
|
||||
:name => 'index_version_associations_on_foreign_key'
|
||||
end
|
||||
|
||||
def self.down
|
||||
remove_index :version_associations, [:version_id]
|
||||
remove_index :version_associations, :name => 'index_version_associations_on_foreign_key'
|
||||
remove_index :version_associations,
|
||||
:name => 'index_version_associations_on_foreign_key'
|
||||
drop_table :version_associations
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -32,7 +32,9 @@ module PaperTrail
|
|||
# set, versions will be narrowed to those pointing at items with those ids
|
||||
# that were created on specified date.
|
||||
def gather_versions(item_id = nil, date = :all)
|
||||
raise ArgumentError.new("`date` argument must receive a Timestamp or `:all`") unless date == :all || date.respond_to?(:to_date)
|
||||
unless date == :all || date.respond_to?(:to_date)
|
||||
raise ArgumentError.new("`date` argument must receive a Timestamp or `:all`")
|
||||
end
|
||||
versions = item_id ? PaperTrail::Version.where(:item_id => item_id) : PaperTrail::Version
|
||||
versions = versions.between(date.to_date, date.to_date + 1.day) unless date == :all
|
||||
|
||||
|
|
|
@ -40,7 +40,8 @@ module PaperTrail
|
|||
|
||||
# Indicates whether PaperTrail is on or off.
|
||||
def enabled
|
||||
PaperTrail.paper_trail_store[:paper_trail_enabled].nil? || PaperTrail.paper_trail_store[:paper_trail_enabled]
|
||||
PaperTrail.paper_trail_store[:paper_trail_enabled].nil? ||
|
||||
PaperTrail.paper_trail_store[:paper_trail_enabled]
|
||||
end
|
||||
|
||||
def enabled= enable
|
||||
|
|
|
@ -76,8 +76,9 @@ module PaperTrail
|
|||
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 }
|
||||
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] ||= {}
|
||||
|
@ -118,9 +119,7 @@ module PaperTrail
|
|||
fail ArgumentError, 'recording order can only be "after" or "before"'
|
||||
end
|
||||
|
||||
send "#{recording_order}_destroy",
|
||||
:record_destroy,
|
||||
:if => :save_version?
|
||||
send "#{recording_order}_destroy", :record_destroy, :if => :save_version?
|
||||
|
||||
return if paper_trail_options[:on].include?(:destroy)
|
||||
paper_trail_options[:on] << :destroy
|
||||
|
@ -128,10 +127,8 @@ module PaperTrail
|
|||
|
||||
# Record version after "update" event
|
||||
def paper_trail_on_update
|
||||
before_save :reset_timestamp_attrs_for_update_if_needed!,
|
||||
:on => :update
|
||||
after_update :record_update,
|
||||
:if => :save_version?
|
||||
before_save :reset_timestamp_attrs_for_update_if_needed!, :on => :update
|
||||
after_update :record_update, :if => :save_version?
|
||||
after_update :clear_version_instance!
|
||||
|
||||
return if paper_trail_options[:on].include?(:update)
|
||||
|
@ -140,8 +137,7 @@ module PaperTrail
|
|||
|
||||
# Record version after "create" event
|
||||
def paper_trail_on_create
|
||||
after_create :record_create,
|
||||
:if => :save_version?
|
||||
after_create :record_create, :if => :save_version?
|
||||
|
||||
return if paper_trail_options[:on].include?(:create)
|
||||
paper_trail_options[:on] << :create
|
||||
|
@ -277,7 +273,9 @@ module PaperTrail
|
|||
|
||||
# Returns the object (not a Version) as it was most recently.
|
||||
def previous_version
|
||||
preceding_version = source_version ? source_version.previous : send(self.class.versions_association_name).last
|
||||
preceding_version = source_version ?
|
||||
source_version.previous :
|
||||
send(self.class.versions_association_name).last
|
||||
preceding_version.reify if preceding_version
|
||||
end
|
||||
|
||||
|
@ -507,7 +505,9 @@ module PaperTrail
|
|||
assoc_version_args.merge!(:foreign_key_id => send(assoc.foreign_key))
|
||||
end
|
||||
|
||||
PaperTrail::VersionAssociation.create(assoc_version_args) if assoc_version_args.has_key?(:foreign_key_id)
|
||||
if assoc_version_args.has_key?(:foreign_key_id)
|
||||
PaperTrail::VersionAssociation.create(assoc_version_args)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -550,7 +550,8 @@ module PaperTrail
|
|||
def attributes_before_change
|
||||
attributes.tap do |prev|
|
||||
enums = self.respond_to?(:defined_enums) ? self.defined_enums : {}
|
||||
changed_attributes.select { |k,v| self.class.column_names.include?(k) }.each do |attr, before|
|
||||
attrs = changed_attributes.select { |k, v| self.class.column_names.include?(k) }
|
||||
attrs.each do |attr, before|
|
||||
before = enums[attr][before] if enums[attr]
|
||||
prev[attr] = before
|
||||
end
|
||||
|
@ -592,7 +593,10 @@ module PaperTrail
|
|||
# Remove Hash arguments and then evaluate whether the attributes (the
|
||||
# keys of the hash) should also get pushed into the collection.
|
||||
only.delete_if do |obj|
|
||||
obj.is_a?(Hash) && obj.each { |attr, condition| only << attr if condition.respond_to?(:call) && condition.call(self) }
|
||||
obj.is_a?(Hash) &&
|
||||
obj.each { |attr, condition|
|
||||
only << attr if condition.respond_to?(:call) && condition.call(self)
|
||||
}
|
||||
end
|
||||
only.empty? ? changed_and_not_ignored : (changed_and_not_ignored & only)
|
||||
end
|
||||
|
@ -602,14 +606,19 @@ module PaperTrail
|
|||
# Remove Hash arguments and then evaluate whether the attributes (the
|
||||
# keys of the hash) should also get pushed into the collection.
|
||||
ignore.delete_if do |obj|
|
||||
obj.is_a?(Hash) && obj.each { |attr, condition| ignore << attr if condition.respond_to?(:call) && condition.call(self) }
|
||||
obj.is_a?(Hash) &&
|
||||
obj.each { |attr, condition|
|
||||
ignore << attr if condition.respond_to?(:call) && condition.call(self)
|
||||
}
|
||||
end
|
||||
skip = self.paper_trail_options[:skip]
|
||||
changed - ignore - skip
|
||||
end
|
||||
|
||||
def paper_trail_switched_on?
|
||||
PaperTrail.enabled? && PaperTrail.enabled_for_controller? && self.paper_trail_enabled_for_model?
|
||||
PaperTrail.enabled? &&
|
||||
PaperTrail.enabled_for_controller? &&
|
||||
self.paper_trail_enabled_for_model?
|
||||
end
|
||||
|
||||
def save_version?
|
||||
|
|
|
@ -85,7 +85,8 @@ module PaperTrail
|
|||
end
|
||||
|
||||
obj = obj.send(PaperTrail.timestamp_field) if obj.is_a?(self)
|
||||
where(arel_table[PaperTrail.timestamp_field].lt(obj)).order(self.timestamp_sort_order('desc'))
|
||||
where(arel_table[PaperTrail.timestamp_field].lt(obj)).
|
||||
order(self.timestamp_sort_order('desc'))
|
||||
end
|
||||
|
||||
def between(start_time, end_time)
|
||||
|
@ -136,7 +137,8 @@ module PaperTrail
|
|||
where_conditions = "object_changes @> '#{args.to_json}'::jsonb"
|
||||
elsif columns_hash['object'].type == :json
|
||||
where_conditions = args.map do |field, value|
|
||||
"((object_changes->>'#{field}' ILIKE '[#{value.to_json},%') OR (object_changes->>'#{field}' ILIKE '[%,#{value.to_json}]%'))"
|
||||
"((object_changes->>'#{field}' ILIKE '[#{value.to_json},%') " +
|
||||
"OR (object_changes->>'#{field}' ILIKE '[%,#{value.to_json}]%'))"
|
||||
end
|
||||
where_conditions = where_conditions.join(" AND ")
|
||||
else
|
||||
|
|
|
@ -37,7 +37,9 @@ Gem::Specification.new do |s|
|
|||
s.add_development_dependency 'pry-nav', '~> 0.2.4'
|
||||
s.add_development_dependency 'rubocop', '~> 0.35.1'
|
||||
|
||||
# Allow time travel in testing. timecop is only supported after 1.9.2 but does a better cleanup at 'return'
|
||||
# Allow time travel in testing. timecop is only supported after 1.9.2 but
|
||||
# does a better cleanup at 'return'.
|
||||
# TODO: We can remove delorean, as we no longer support ruby < 1.9.3
|
||||
if RUBY_VERSION < "1.9.2"
|
||||
s.add_development_dependency 'delorean'
|
||||
else
|
||||
|
|
Loading…
Reference in New Issue