Class: Decidim::FilterResource::Filter

Inherits:
Object
  • Object
show all
Defined in:
decidim-core/app/controllers/concerns/decidim/filter_resource.rb

Overview

Internal: Defines a class that will wrap in an object the URL params used by the filter. this way we can use Rails’ form helpers and have automatically checked checkboxes and radio buttons in the view, for example.

Instance Method Summary collapse

Constructor Details

#initialize(filter) ⇒ Filter

Returns a new instance of Filter.



14
15
16
# File 'decidim-core/app/controllers/concerns/decidim/filter_resource.rb', line 14

def initialize(filter)
  @filter = filter
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *_arguments) ⇒ Object



18
19
20
21
# File 'decidim-core/app/controllers/concerns/decidim/filter_resource.rb', line 18

def method_missing(method_name, *_arguments)
  method = method_name.to_s.gsub(/\[[0-9]+\]$/, "").to_sym
  @filter.present? && @filter.has_key?(method) ? @filter[method] : super
end

Instance Method Details

#respond_to_missing?(method_name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
26
# File 'decidim-core/app/controllers/concerns/decidim/filter_resource.rb', line 23

def respond_to_missing?(method_name, include_private = false)
  method = method_name.to_s.gsub(/\[[0-9]+\]$/, "").to_sym
  (@filter.present? && @filter.has_key?(method)) || super
end