Class: JsonApiServer::FilterBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/json_api_server/filter_builders.rb

Overview

Base filter/query builder class. All should inherit from this class.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attr, value, operator, config) ⇒ FilterBuilder

Returns a new instance of FilterBuilder.



16
17
18
19
20
21
22
# File 'lib/json_api_server/filter_builders.rb', line 16

def initialize(attr, value, operator, config)
  @attr = attr
  @value = value
  @config = config
  @column_name = @config.column_name
  @operator = operator
end

Instance Attribute Details

#attrObject (readonly)

The filter attribute, i.e., filter



5
6
7
# File 'lib/json_api_server/filter_builders.rb', line 5

def attr
  @attr
end

#column_nameObject (readonly)

Column name in the database. Specified when the filter name in the query doesn’t match the column name in the database.



12
13
14
# File 'lib/json_api_server/filter_builders.rb', line 12

def column_name
  @column_name
end

#configObject (readonly)

Instance of FilterConfig for the specific attribute/column.



9
10
11
# File 'lib/json_api_server/filter_builders.rb', line 9

def config
  @config
end

#operatorObject (readonly)

Can be IN, <, >, <=, etc.



14
15
16
# File 'lib/json_api_server/filter_builders.rb', line 14

def operator
  @operator
end

#valueObject (readonly)

Casted value(s). If value included a common, an array of casted values.



7
8
9
# File 'lib/json_api_server/filter_builders.rb', line 7

def value
  @value
end

Instance Method Details

#to_query(_model) ⇒ Object

Subclasses must implement. Can return an ActiveRecord::Relation or nil.



26
27
28
# File 'lib/json_api_server/filter_builders.rb', line 26

def to_query(_model)
  raise 'subclasses should implement this method.'
end