From 9f689c21a248d7d12883e8c4cf8ec91c85746326 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Sat, 22 Aug 2020 23:30:53 +0200 Subject: [PATCH] Rename filter method to filter_by Ruby 2.6 introduces `Enumerable#filter` as an alias to `Enumerable#select`, and so our Filterable.filter method will not work with Ruby 2.6. So we're renaming the method to `filter_by`, which is similar to `find_by`. We could also change the `filter` method so if a block is given it delegates to `Enumerable#filter`, the same way ActiveRecord handles the `select` method, but IMHO this is easier to follow. --- app/controllers/concerns/commentable_actions.rb | 2 +- app/models/budget/investment.rb | 2 +- app/models/concerns/filterable.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/concerns/commentable_actions.rb b/app/controllers/concerns/commentable_actions.rb index 86f47b4d6..8b2a6d3bc 100644 --- a/app/controllers/concerns/commentable_actions.rb +++ b/app/controllers/concerns/commentable_actions.rb @@ -9,7 +9,7 @@ module CommentableActions @resources = @current_order == "recommendations" && current_user.present? ? @resources.recommendations(current_user) : @resources.for_render @resources = @resources.search(@search_terms) if @search_terms.present? - @resources = @advanced_search_terms.present? ? @resources.filter(@advanced_search_terms) : @resources + @resources = @advanced_search_terms.present? ? @resources.filter_by(@advanced_search_terms) : @resources @resources = @resources.page(params[:page]).send("sort_by_#{@current_order}") diff --git a/app/models/budget/investment.rb b/app/models/budget/investment.rb index 4adf23556..8258bcc6b 100644 --- a/app/models/budget/investment.rb +++ b/app/models/budget/investment.rb @@ -357,7 +357,7 @@ class Budget investments = investments.send(current_filter) if current_filter.present? investments = investments.by_heading(params[:heading_id]) if params[:heading_id].present? investments = investments.search(params[:search]) if params[:search].present? - investments = investments.filter(params[:advanced_search]) if params[:advanced_search].present? + investments = investments.filter_by(params[:advanced_search]) if params[:advanced_search].present? investments end diff --git a/app/models/concerns/filterable.rb b/app/models/concerns/filterable.rb index e25471c23..31d64ae89 100644 --- a/app/models/concerns/filterable.rb +++ b/app/models/concerns/filterable.rb @@ -7,7 +7,7 @@ module Filterable end class_methods do - def filter(params) + def filter_by(params) resources = all params.each do |filter, value| if allowed_filter?(filter, value)