class HQ::GraphQL::Filters::Filter
Attributes
column[R]
operation[R]
table[R]
value[R]
Public Class Methods
class_from_column(column)
click to toggle source
# File lib/hq/graphql/filters.rb, line 47 def self.class_from_column(column) case column.type when :boolean BooleanFilter when :date, :datetime DateFilter when :decimal, :integer NumericFilter when :string, :text StringFilter when :uuid UuidFilter end end
for(filter, **options)
click to toggle source
# File lib/hq/graphql/filters.rb, line 43 def self.for(filter, **options) class_from_column(filter.field).new(filter, **options) end
new(filter, table:)
click to toggle source
# File lib/hq/graphql/filters.rb, line 78 def initialize(filter, table:) @table = table @column = filter.field @operation = filter.operation @value = filter.value end
validate_operations(*operations)
click to toggle source
# File lib/hq/graphql/filters.rb, line 62 def self.validate_operations(*operations) valid_operations = operations + [WITH] validates :operation, inclusion: { in: valid_operations, message: "only supports the following operations: #{valid_operations.map(&:name).join(", ")}" } end
validate_value(**options)
click to toggle source
# File lib/hq/graphql/filters.rb, line 70 def self.validate_value(**options) validates :value, **options, unless: ->(filter) { filter.operation == WITH } end
Public Instance Methods
display_error_message()
click to toggle source
# File lib/hq/graphql/filters.rb, line 85 def display_error_message return unless errors.any? messages = errors.messages.values.join(", ") "#{column.name.camelize(:lower)} (type: #{column.type}, operation: #{operation.name}, value: \"#{value}\"): #{messages}" end
to_arel()
click to toggle source
# File lib/hq/graphql/filters.rb, line 91 def to_arel operation.to_arel(table: table, column_name: column.name, value: value) end
validate_boolean_values()
click to toggle source
# File lib/hq/graphql/filters.rb, line 95 def validate_boolean_values is_valid = BOOLEAN_VALUES.any? { |v| value.casecmp(v) == 0 } return if is_valid errors.add(:value, "WITH operation only supports boolean values (#{BOOLEAN_VALUES.join(", ")})") end