class Spree::Core::QueryFilters::Text

Attributes

attribute[R]

Public Class Methods

new(attribute:) click to toggle source
# File lib/spree/core/query_filters/text.rb, line 5
def initialize(attribute:)
  @attribute = attribute
end

Public Instance Methods

call(scope:, filter:) click to toggle source
# File lib/spree/core/query_filters/text.rb, line 9
def call(scope:, filter:)
  scope = eq(scope, filter[:eq])
  contains(scope, filter[:contains])
end

Private Instance Methods

contains(scope, value) click to toggle source
# File lib/spree/core/query_filters/text.rb, line 24
def contains(scope, value)
  return scope unless value

  scope.where(attribute.matches("%#{value}%"))
end
eq(scope, value) click to toggle source
# File lib/spree/core/query_filters/text.rb, line 18
def eq(scope, value)
  return scope unless value

  scope.where(attribute.eq(value))
end