Sha256: 364b435c0d96d1a709f7e8d7001d2a75712b9d0d5141b5c6a377e8f3b3a2babd

Contents?: true

Size: 631 Bytes

Versions: 22

Compression:

Stored size: 631 Bytes

Contents

class Agilibox::SmallData::FilterStrategyByKeyValue < ::Agilibox::SmallData::FilterStrategy
  attr_reader :key

  def initialize(key = nil)
    @key = key
  end

  def apply(query, value)
    value = true  if value == "true"
    value = false if value == "false"

    column = column_for(query)

    if value.to_s.in?(%w(nil null))
      query.where("#{column} IS NULL")
    elsif value.to_s.in?(%w(not_nil not_null))
      query.where("#{column} IS NOT NULL")
    else
      query.where("#{column} = ?", value)
    end
  end

  def column_for(query)
    key.is_a?(Symbol) ? "#{query.model.table_name}.#{key}" : key.to_s
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
agilibox-1.9.5 app/filters/agilibox/small_data/filter_strategy_by_key_value.rb
agilibox-1.9.4 app/filters/agilibox/small_data/filter_strategy_by_key_value.rb
agilibox-1.9.3 app/filters/agilibox/small_data/filter_strategy_by_key_value.rb
agilibox-1.9.1 app/filters/agilibox/small_data/filter_strategy_by_key_value.rb
agilibox-1.9.0 app/filters/agilibox/small_data/filter_strategy_by_key_value.rb
agilibox-1.8.0 app/filters/agilibox/small_data/filter_strategy_by_key_value.rb
agilibox-1.7.4 app/filters/agilibox/small_data/filter_strategy_by_key_value.rb
agilibox-1.7.3 app/filters/agilibox/small_data/filter_strategy_by_key_value.rb
agilibox-1.7.2 app/filters/agilibox/small_data/filter_strategy_by_key_value.rb
agilibox-1.7.1 app/filters/agilibox/small_data/filter_strategy_by_key_value.rb
agilibox-1.7.0 app/filters/agilibox/small_data/filter_strategy_by_key_value.rb
agilibox-1.6.2 app/filters/agilibox/small_data/filter_strategy_by_key_value.rb
agilibox-1.6.1 app/filters/agilibox/small_data/filter_strategy_by_key_value.rb
agilibox-1.6.0 app/filters/agilibox/small_data/filter_strategy_by_key_value.rb
agilibox-1.5.13 app/filters/agilibox/small_data/filter_strategy_by_key_value.rb
agilibox-1.5.12 app/filters/agilibox/small_data/filter_strategy_by_key_value.rb
agilibox-1.5.11 app/filters/agilibox/small_data/filter_strategy_by_key_value.rb
agilibox-1.5.10 app/filters/agilibox/small_data/filter_strategy_by_key_value.rb
agilibox-1.5.9 app/filters/agilibox/small_data/filter_strategy_by_key_value.rb
agilibox-1.5.8 app/filters/agilibox/small_data/filter_strategy_by_key_value.rb