Skip to content

Commit

Permalink
normalized aliasing with alias_method
Browse files Browse the repository at this point in the history
  • Loading branch information
ddnexus committed May 23, 2019
1 parent 3c60d9b commit bd3be09
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions lib/pagy/extras/i18n.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ module Frontend

Pagy::I18n.clear.instance_eval { undef :load; undef :t } # unload the pagy default constant for efficiency

alias :pagy_without_i18n :pagy_t
alias_method :pagy_without_i18n, :pagy_t
def pagy_t_with_i18n(*args) ::I18n.t(*args) end
alias :pagy_t :pagy_t_with_i18n
alias_method :pagy_t, :pagy_t_with_i18n

end
end
8 changes: 4 additions & 4 deletions lib/pagy/extras/overflow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Pagy

def overflow?; @overflow end

alias :initialize_without_overflow :initialize
alias_method :initialize_without_overflow, :initialize
def initialize_with_overflow(vars)
@overflow ||= false # don't override if :last_page re-run the method after an overflow
initialize_without_overflow(vars)
Expand All @@ -31,7 +31,7 @@ def initialize_with_overflow(vars)
raise ArgumentError, "expected :overflow variable in [:last_page, :empty_page, :exception]; got #{@vars[:overflow].inspect}"
end
end
alias :initialize :initialize_with_overflow
alias_method :initialize, :initialize_with_overflow

module Series
def series(size=@vars[:size])
Expand All @@ -48,7 +48,7 @@ def series(size=@vars[:size])
if defined?(Pagy::Countless)
class Countless

alias :finalize_without_overflow :finalize
alias_method :finalize_without_overflow, :finalize
def finalize_with_overflow(items)
@overflow = false
finalize_without_overflow(items)
Expand All @@ -65,7 +65,7 @@ def finalize_with_overflow(items)
raise ArgumentError, "expected :overflow variable in [:empty_page, :exception]; got #{@vars[:overflow].inspect}"
end
end
alias :finalize :finalize_with_overflow
alias_method :finalize, :finalize_with_overflow

end
end
Expand Down
2 changes: 1 addition & 1 deletion test/mock_helpers/searchkick.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def initialize(query, options={}, &block)
def results
@results.map{|r| "R-#{r}"}
end
alias :records :results # enables loops in items_test
alias_method :records, :results # enables loops in items_test

def total_count
@entries.size
Expand Down

0 comments on commit bd3be09

Please sign in to comment.