Class: Toller::Filter

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

Overview

Filter

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parameter, type, options) ⇒ Filter

Returns a new instance of Filter.



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

def initialize(parameter, type, options)
  @parameter = parameter
  @type = type
  @properties = options.reverse_merge(
    field: parameter,
    default: false,
    scope_name: nil
  )
end

Instance Attribute Details

#parameterObject (readonly)

Returns the value of attribute parameter.



8
9
10
# File 'lib/toller/filter.rb', line 8

def parameter
  @parameter
end

#propertiesObject (readonly)

Returns the value of attribute properties.



8
9
10
# File 'lib/toller/filter.rb', line 8

def properties
  @properties
end

#typeObject (readonly)

Returns the value of attribute type.



8
9
10
# File 'lib/toller/filter.rb', line 8

def type
  @type
end

Instance Method Details

#apply!(collection, value) ⇒ Object



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

def apply!(collection, value)
  if type == :scope
    Filters::ScopeHandler.new.call(collection, value, properties)
  else
    Filters::WhereHandler.new.call(collection, type, value, properties)
  end
end

#defaultObject



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

def default
  properties[:default]
end