Class: HQ::GraphQL::FilterOperations::Operation
- Inherits:
-
Object
- Object
- HQ::GraphQL::FilterOperations::Operation
- Defined in:
- lib/hq/graphql/filter_operations.rb
Instance Attribute Summary collapse
-
#arel ⇒ Object
readonly
Returns the value of attribute arel.
-
#check_for_null ⇒ Object
readonly
Returns the value of attribute check_for_null.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#sanitize ⇒ Object
readonly
Returns the value of attribute sanitize.
Instance Method Summary collapse
-
#initialize(name:, arel:, check_for_null: false, sanitize: nil) ⇒ Operation
constructor
A new instance of Operation.
- #sanitize_value(value) ⇒ Object
- #to_arel(table:, column_name:, value:) ⇒ Object
Constructor Details
#initialize(name:, arel:, check_for_null: false, sanitize: nil) ⇒ Operation
Returns a new instance of Operation.
11 12 13 14 15 16 |
# File 'lib/hq/graphql/filter_operations.rb', line 11 def initialize(name:, arel:, check_for_null: false, sanitize: nil) @name = name @arel = arel @check_for_null = check_for_null @sanitize = sanitize end |
Instance Attribute Details
#arel ⇒ Object (readonly)
Returns the value of attribute arel.
9 10 11 |
# File 'lib/hq/graphql/filter_operations.rb', line 9 def arel @arel end |
#check_for_null ⇒ Object (readonly)
Returns the value of attribute check_for_null.
9 10 11 |
# File 'lib/hq/graphql/filter_operations.rb', line 9 def check_for_null @check_for_null end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
9 10 11 |
# File 'lib/hq/graphql/filter_operations.rb', line 9 def name @name end |
#sanitize ⇒ Object (readonly)
Returns the value of attribute sanitize.
9 10 11 |
# File 'lib/hq/graphql/filter_operations.rb', line 9 def sanitize @sanitize end |
Instance Method Details
#sanitize_value(value) ⇒ Object
18 19 20 |
# File 'lib/hq/graphql/filter_operations.rb', line 18 def sanitize_value(value) sanitize ? sanitize.call(value) : value end |
#to_arel(table:, column_name:, value:) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/hq/graphql/filter_operations.rb', line 22 def to_arel(table:, column_name:, value:) sanitized_value = sanitize_value(value) if arel.is_a?(Proc) return arel.call(table: table, column_name: column_name, value: sanitized_value) end expression = table[column_name].send(arel, sanitized_value) if check_for_null expression = expression.or(table[column_name].eq(nil)) end expression end |