Class: Rails::Surrender::FilterBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/rails/surrender/helpers/filter_builder.rb

Overview

apply filtering directives to the given resource, based on the given filter controls

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resource:, filter:) ⇒ FilterBuilder

Returns a new instance of FilterBuilder.



9
10
11
12
# File 'lib/rails/surrender/helpers/filter_builder.rb', line 9

def initialize(resource:, filter:)
  @resource = resource
  @filter = filter
end

Instance Attribute Details

#filterObject (readonly)

Returns the value of attribute filter.



7
8
9
# File 'lib/rails/surrender/helpers/filter_builder.rb', line 7

def filter
  @filter
end

#resourceObject (readonly)

Returns the value of attribute resource.



7
8
9
# File 'lib/rails/surrender/helpers/filter_builder.rb', line 7

def resource
  @resource
end

Instance Method Details

#build!Object



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/rails/surrender/helpers/filter_builder.rb', line 14

def build!
  return resource unless resource.is_a?(ActiveRecord::Relation)

  filter.each do |term|
    scope, value = term.first

    send_filter_for(scope, value)
  end

  resource
end