Files
grecia/app/controllers/concerns/has_orders.rb
Javi Martín fdfdbcbd0d Add and apply Style/ArgumentsForwarding rule
We were using generic names like `args` and `options` which don't really
add anything to `*` or `**` because Ruby required us to.

That's no longer the case in Ruby 3.2, so we can simplify the code a
bit.
2024-04-11 17:59:40 +02:00

19 lines
545 B
Ruby

module HasOrders
extend ActiveSupport::Concern
attr_reader :valid_orders, :current_order
included do
helper_method :valid_orders, :current_order
end
class_methods do
def has_orders(valid_orders, *)
before_action(*) do |c|
@valid_orders = valid_orders.respond_to?(:call) ? valid_orders.call(c) : valid_orders.dup
@valid_orders.delete("relevance") if params[:search].blank?
@current_order = @valid_orders.include?(params[:order]) ? params[:order] : @valid_orders.first
end
end
end
end