From 1f3c86f1955407847cef7b1534e07f826e6c039b Mon Sep 17 00:00:00 2001 From: Domizio Demichelis Date: Sun, 27 Jan 2019 21:09:10 +0700 Subject: [PATCH] fixed warnings and a few backward incompatible statements --- lib/locales/plurals.rb | 6 +++--- lib/pagy/countless.rb | 2 +- lib/pagy/extras/items.rb | 2 +- lib/pagy/extras/support.rb | 2 +- lib/pagy/extras/trim.rb | 2 +- lib/pagy/frontend.rb | 6 +++--- test/test_helper/backend.rb | 2 +- 7 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/locales/plurals.rb b/lib/locales/plurals.rb index 69e7e82df..0ac24ed06 100644 --- a/lib/locales/plurals.rb +++ b/lib/locales/plurals.rb @@ -13,9 +13,9 @@ # A plural proc returns a plural type string based on the passed count # Each plural proc may apply to one or more languages below plurals = { - zero_one_other: -> (count) {zero_one[count] || 'other'}, + zero_one_other: lambda {|count| zero_one[count] || 'other'}, - zero_one_few_many_other: -> (count) do + zero_one_few_many_other: lambda do |count| mod10, mod100 = count % 10, count % 100 if count == 0 ; 'zero' elsif mod10 == 1 && mod100 != 11 ; 'one' @@ -25,7 +25,7 @@ end end, - pl: -> (count) do + pl: lambda do |count| mod10, mod100 = count % 10, count % 100 if count == 0 ; 'zero' elsif count == 1 ; 'one' diff --git a/lib/pagy/countless.rb b/lib/pagy/countless.rb index 3387a52b8..18e60c5ec 100644 --- a/lib/pagy/countless.rb +++ b/lib/pagy/countless.rb @@ -6,7 +6,7 @@ class Countless < Pagy # Merge and validate the options, do some simple arithmetic and set a few instance variables def initialize(vars={}) - @vars ||= VARS.merge(vars.delete_if{|_,v| v.nil? || v == '' }) # default vars + cleaned vars (can be overridden) + @vars = VARS.merge(vars.delete_if{|_,v| v.nil? || v == '' }) # default vars + cleaned vars (can be overridden) { items:1, outset:0, page:1 }.each do |k,min| # validate instance variables (@vars[k] && instance_variable_set(:"@#{k}", @vars[k].to_i) >= min) \ or raise(ArgumentError, "expected :#{k} >= #{min}; got #{@vars[k].inspect}") diff --git a/lib/pagy/extras/items.rb b/lib/pagy/extras/items.rb index 2a8eb9add..f3ce46790 100644 --- a/lib/pagy/extras/items.rb +++ b/lib/pagy/extras/items.rb @@ -14,7 +14,7 @@ module Backend ; private def pagy_with_items(vars) vars[:items] ||= (items = params[vars[:items_param] || VARS[:items_param]]) && # :items from :items_param - [items&.to_i, vars.key?(:max_items) ? vars[:max_items] : VARS[:max_items]].compact.min # :items capped to :max_items + [items.to_i, vars.key?(:max_items) ? vars[:max_items] : VARS[:max_items]].compact.min # :items capped to :max_items end alias_method :pagy_get_vars_without_items, :pagy_get_vars diff --git a/lib/pagy/extras/support.rb b/lib/pagy/extras/support.rb index f115e30f4..69d74e7ab 100644 --- a/lib/pagy/extras/support.rb +++ b/lib/pagy/extras/support.rb @@ -6,7 +6,7 @@ class Pagy def to_h - { count: @count, + { count: defined?(@count) && @count, page: @page, items: @items, pages: @pages, diff --git a/lib/pagy/extras/trim.rb b/lib/pagy/extras/trim.rb index 874b25502..d34727329 100644 --- a/lib/pagy/extras/trim.rb +++ b/lib/pagy/extras/trim.rb @@ -15,7 +15,7 @@ def pagy_link_proc_with_trim(pagy, link_extra='') page1_url = pagy_trim_url(marker_url, "#{p_vars[:page_param]}=#{MARKER}") page1_link = %( (n, text=n, extra='') { start = n.to_i == 1 ? page1_link : "#{a}#{n}#{b}" + lambda{|n, text=n, extra=''| start = n.to_i == 1 ? page1_link : "#{a}#{n}#{b}" "#{start}#{ if n == p_prev ; ' rel="prev"' elsif n == p_next ; ' rel="next"' else '' end } #{extra}>#{text}" } diff --git a/lib/pagy/frontend.rb b/lib/pagy/frontend.rb index 17ddd3e70..ff52d3d21 100644 --- a/lib/pagy/frontend.rb +++ b/lib/pagy/frontend.rb @@ -52,9 +52,9 @@ def pagy_get_params(params) params end def pagy_link_proc(pagy, link_extra='') p_prev, p_next = pagy.prev, pagy.next a, b = %( (n, text=n, extra='') { "#{a}#{n}#{b}#{ if n == p_prev ; ' rel="prev"' - elsif n == p_next ; ' rel="next"' - else '' end } #{extra}>#{text}" } + lambda {|n, text=n, extra=''| "#{a}#{n}#{b}#{ if n == p_prev ; ' rel="prev"' + elsif n == p_next ; ' rel="next"' + else '' end } #{extra}>#{text}" } end # Pagy::Frontend::I18N diff --git a/test/test_helper/backend.rb b/test/test_helper/backend.rb index dd02b31ad..6f0c4c4fc 100644 --- a/test/test_helper/backend.rb +++ b/test/test_helper/backend.rb @@ -34,7 +34,7 @@ def count(*) class TestGroupedCollection < TestCollection def count(*) - @collection.map { |value| [value, value + 1] }.to_h + Hash[@collection.map { |value| [value, value + 1] }] end end