Sha256: bcff7cfc6b910a95fc9445a55b46d7be5f57b228afd498eafad6e52d7d4dc5ac

Contents?: true

Size: 643 Bytes

Versions: 21

Compression:

Stored size: 643 Bytes

Contents

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

  def initialize(key = nil)
    super()
    @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

21 entries across 21 versions & 1 rubygems

Version Path
agilibox-2.0.0 app/filters/agilibox/small_data/filter_strategy_by_key_value.rb
agilibox-1.11.0 app/filters/agilibox/small_data/filter_strategy_by_key_value.rb
agilibox-1.10.5 app/filters/agilibox/small_data/filter_strategy_by_key_value.rb
agilibox-1.10.2 app/filters/agilibox/small_data/filter_strategy_by_key_value.rb
agilibox-1.10.1 app/filters/agilibox/small_data/filter_strategy_by_key_value.rb
agilibox-1.10.0 app/filters/agilibox/small_data/filter_strategy_by_key_value.rb
agilibox-1.9.20 app/filters/agilibox/small_data/filter_strategy_by_key_value.rb
agilibox-1.9.19 app/filters/agilibox/small_data/filter_strategy_by_key_value.rb
agilibox-1.9.18 app/filters/agilibox/small_data/filter_strategy_by_key_value.rb
agilibox-1.9.17 app/filters/agilibox/small_data/filter_strategy_by_key_value.rb
agilibox-1.9.16 app/filters/agilibox/small_data/filter_strategy_by_key_value.rb
agilibox-1.9.15 app/filters/agilibox/small_data/filter_strategy_by_key_value.rb
agilibox-1.9.14 app/filters/agilibox/small_data/filter_strategy_by_key_value.rb
agilibox-1.9.13 app/filters/agilibox/small_data/filter_strategy_by_key_value.rb
agilibox-1.9.12 app/filters/agilibox/small_data/filter_strategy_by_key_value.rb
agilibox-1.9.11 app/filters/agilibox/small_data/filter_strategy_by_key_value.rb
agilibox-1.9.10 app/filters/agilibox/small_data/filter_strategy_by_key_value.rb
agilibox-1.9.9 app/filters/agilibox/small_data/filter_strategy_by_key_value.rb
agilibox-1.9.8 app/filters/agilibox/small_data/filter_strategy_by_key_value.rb
agilibox-1.9.7 app/filters/agilibox/small_data/filter_strategy_by_key_value.rb