From b6fb7bae29621afa3839901d0c9afe42401db975 Mon Sep 17 00:00:00 2001 From: Paul Padier Date: Thu, 31 Mar 2016 17:57:32 +0900 Subject: [PATCH] Fix Style/Alias offenses --- .rubocop_todo.yml | 13 ------------- lib/paper_trail.rb | 3 +-- lib/paper_trail/config.rb | 3 +-- lib/paper_trail/has_paper_trail.rb | 2 ++ lib/paper_trail/version_concern.rb | 2 +- test/dummy/app/models/song.rb | 8 ++++---- 6 files changed, 9 insertions(+), 22 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 6ca9825b..b35a654a 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -18,19 +18,6 @@ Metrics/ModuleLength: Metrics/PerceivedComplexity: Max: 16 -# Offense count: 11 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -# SupportedStyles: prefer_alias, prefer_alias_method -Style/Alias: - Exclude: - - 'lib/paper_trail.rb' - - 'lib/paper_trail/config.rb' - - 'lib/paper_trail/has_paper_trail.rb' - - 'lib/paper_trail/version_concern.rb' - - 'test/dummy/app/models/song.rb' - - 'test/unit/model_test.rb' - # Offense count: 33 Style/Documentation: Enabled: false diff --git a/lib/paper_trail.rb b/lib/paper_trail.rb index 5d26faab..b627f209 100644 --- a/lib/paper_trail.rb +++ b/lib/paper_trail.rb @@ -154,8 +154,7 @@ module PaperTrail yield @config if block_given? @config end - - alias_method :configure, :config + alias configure config end end diff --git a/lib/paper_trail/config.rb b/lib/paper_trail/config.rb index 95dac70c..4df3ddd2 100644 --- a/lib/paper_trail/config.rb +++ b/lib/paper_trail/config.rb @@ -32,14 +32,13 @@ module PaperTrail ) end - def track_associations + def track_associations? if @track_associations.nil? PaperTrail::VersionAssociation.table_exists? else @track_associations end end - alias_method :track_associations?, :track_associations # Indicates whether PaperTrail is on or off. Default: true. def enabled diff --git a/lib/paper_trail/has_paper_trail.rb b/lib/paper_trail/has_paper_trail.rb index a1eb2f42..530f5e0f 100644 --- a/lib/paper_trail/has_paper_trail.rb +++ b/lib/paper_trail/has_paper_trail.rb @@ -255,6 +255,7 @@ module PaperTrail # Utility method for reifying. Anything executed inside the block will # appear like a new record. + # rubocop: disable Style/Alias def appear_as_new_record instance_eval { alias :old_new_record? :new_record? @@ -263,6 +264,7 @@ module PaperTrail yield instance_eval { alias :new_record? :old_new_record? } end + # rubocop: enable Style/Alias # Temporarily overwrites the value of whodunnit and then executes the # provided block. diff --git a/lib/paper_trail/version_concern.rb b/lib/paper_trail/version_concern.rb index 978e2aec..a4ba7c33 100644 --- a/lib/paper_trail/version_concern.rb +++ b/lib/paper_trail/version_concern.rb @@ -242,7 +242,7 @@ module PaperTrail def terminator @terminator ||= whodunnit end - alias_method :version_author, :terminator + alias version_author terminator def sibling_versions(reload = false) if reload || @sibling_versions.nil? diff --git a/test/dummy/app/models/song.rb b/test/dummy/app/models/song.rb index 21fc3de1..6e02dada 100644 --- a/test/dummy/app/models/song.rb +++ b/test/dummy/app/models/song.rb @@ -23,8 +23,8 @@ class Song < ActiveRecord::Base # `alias_method_chain` is deprecated in rails 5, but we cannot use the # suggested replacement, `Module#prepend`, because we still support ruby 1.9. - alias_method :attributes_without_name, :attributes - alias_method :attributes, :attributes_with_name + alias attributes_without_name attributes + alias attributes attributes_with_name def changed_attributes_with_name if name @@ -36,6 +36,6 @@ class Song < ActiveRecord::Base # `alias_method_chain` is deprecated in rails 5, but we cannot use the # suggested replacement, `Module#prepend`, because we still support ruby 1.9. - alias_method :changed_attributes_without_name, :changed_attributes - alias_method :changed_attributes, :changed_attributes_with_name + alias changed_attributes_without_name changed_attributes + alias changed_attributes changed_attributes_with_name end