Skip to content

Commit

Permalink
Merge pull request #758 from magni-/rubocop_alias
Browse files Browse the repository at this point in the history
Fix Style/Alias offenses
  • Loading branch information
jaredbeck committed Apr 8, 2016
2 parents 830d48a + b6fb7ba commit 9658088
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 @@ -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
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,14 +32,13 @@ def serialized_attributes=(_)
)
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
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 @@ -255,6 +255,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 @@ -263,6 +264,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 @@ -242,7 +242,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 9658088

Please sign in to comment.