Skip to content

Commit

Permalink
Fix Style/Alias offenses
Browse files Browse the repository at this point in the history
  • Loading branch information
magni- committed Apr 5, 2016
1 parent e78fedf commit 8dfe537
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 22 deletions.
13 changes: 0 additions & 13 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,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'

# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: nested, compact
Style/ClassAndModuleChildren:
Expand Down
3 changes: 1 addition & 2 deletions lib/paper_trail.rb
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,7 @@ def config
yield @config if block_given?
@config
end

alias_method :configure, :config
alias configure config
end
end

Expand Down
3 changes: 1 addition & 2 deletions lib/paper_trail/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,11 @@ def serialized_attributes=(_)
)
end

def track_associations
def track_associations?
@track_associations.nil? ?
PaperTrail::VersionAssociation.table_exists? :
@track_associations
end
alias_method :track_associations?, :track_associations

# Indicates whether PaperTrail is on or off. Default: true.
def enabled
Expand Down
2 changes: 2 additions & 0 deletions lib/paper_trail/has_paper_trail.rb
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ def without_versioning(method = nil)

# 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?
Expand All @@ -260,6 +261,7 @@ def appear_as_new_record
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.
Expand Down
2 changes: 1 addition & 1 deletion lib/paper_trail/version_concern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ def originator
def terminator
@terminator ||= whodunnit
end
alias_method :version_author, :terminator
alias version_author terminator

def sibling_versions(reload = false)
if reload || @sibling_versions.nil?
Expand Down
8 changes: 4 additions & 4 deletions test/dummy/app/models/song.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ def attributes_with_name

# `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
Expand All @@ -36,6 +36,6 @@ def changed_attributes_with_name

# `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

0 comments on commit 8dfe537

Please sign in to comment.