Class: Resourcey::Filter

Inherits:
Object
  • Object
show all
Defined in:
lib/resourcey/filter.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ Filter

Returns a new instance of Filter.



6
7
8
# File 'lib/resourcey/filter.rb', line 6

def initialize(params)
  @permitted_params = params.permit(self.allowed_params)
end

Class Method Details

.build_filter(filter_name, opts, &block) ⇒ Object



28
29
30
# File 'lib/resourcey/filter.rb', line 28

def build_filter(filter_name, opts, &block)
  FilterProcessor.new(filter_name, opts, &block)
end

.filter(filter_name, opts = {}, &block) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/resourcey/filter.rb', line 20

def filter(filter_name, opts = {}, &block)
  self.allowed_params ||= []
  self.allowed_params << filter_name

  self.filters ||= []
  self.filters << build_filter(filter_name, opts, &block)
end

Instance Method Details

#apply(scope) ⇒ Object



10
11
12
13
14
15
16
17
# File 'lib/resourcey/filter.rb', line 10

def apply(scope)
  @permitted_params.each do |filter_name, permitted_param|
    filter = self.filters.find { |filter| filter.name == filter_name }
    scope = filter.apply(permitted_param, scope)
  end

  scope
end