Class: HQ::GraphQL::Filters
- Inherits:
-
Object
- Object
- HQ::GraphQL::Filters
- Defined in:
- lib/hq/graphql/filters.rb
Defined Under Namespace
Classes: BooleanFilter, DateFilter, Filter, NumericFilter, StringFilter, UuidFilter
Constant Summary collapse
- BOOLEAN_VALUES =
["t", "f", "true", "false"]
Instance Attribute Summary collapse
-
#filters ⇒ Object
readonly
Returns the value of attribute filters.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(filters, model) ⇒ Filters
constructor
A new instance of Filters.
- #to_scope ⇒ Object
- #validate! ⇒ Object
Constructor Details
Instance Attribute Details
#filters ⇒ Object (readonly)
Returns the value of attribute filters.
15 16 17 |
# File 'lib/hq/graphql/filters.rb', line 15 def filters @filters end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
15 16 17 |
# File 'lib/hq/graphql/filters.rb', line 15 def model @model end |
Class Method Details
.supported?(column) ⇒ Boolean
11 12 13 |
# File 'lib/hq/graphql/filters.rb', line 11 def self.supported?(column) !!Filter.class_from_column(column) end |
Instance Method Details
#to_scope ⇒ Object
33 34 35 36 37 |
# File 'lib/hq/graphql/filters.rb', line 33 def to_scope filters.reduce(model.all) do |s, filter| s.where(filter.to_arel) end end |
#validate! ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/hq/graphql/filters.rb', line 22 def validate! filters.each(&:validate) errors = filters.map do |filter| filter. end.flatten.uniq if errors.any? raise ::GraphQL::ExecutionError, errors.join(", ") end end |