Class: JsonApiServer::FilterBuilder
- Inherits:
-
Object
- Object
- JsonApiServer::FilterBuilder
- Defined in:
- lib/json_api_server/filter_builders.rb
Overview
Base filter/query builder class. All should inherit from this class.
Direct Known Subclasses
ModelQuery, PgIlike, PgJsonbArray, PgJsonbIlikeArray, SqlComp, SqlEql, SqlIn, SqlLike
Instance Attribute Summary collapse
-
#attr ⇒ Object
readonly
The filter attribute, i.e., filter.
-
#column_name ⇒ Object
readonly
Column name in the database.
-
#config ⇒ Object
readonly
Instance of FilterConfig for the specific attribute/column.
-
#operator ⇒ Object
readonly
Can be IN, <, >, <=, etc.
-
#value ⇒ Object
readonly
Casted value(s).
Instance Method Summary collapse
-
#initialize(attr, value, operator, config) ⇒ FilterBuilder
constructor
A new instance of FilterBuilder.
-
#to_query(_model) ⇒ Object
Subclasses must implement.
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
#attr ⇒ Object (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_name ⇒ Object (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 |
#config ⇒ Object (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 |
#operator ⇒ Object (readonly)
Can be IN, <, >, <=, etc.
14 15 16 |
# File 'lib/json_api_server/filter_builders.rb', line 14 def operator @operator end |
#value ⇒ Object (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 |