Sha256: 5d38c8e1736881544eab172f95967bfc08dede00f6d36208a4b5e599a07f6deb
Contents?: true
Size: 616 Bytes
Versions: 2
Compression:
Stored size: 616 Bytes
Contents
class BMC::Filter::ByKeyValue attr_reader :key def initialize(key = nil) super() @key = key end def call(query, value) return query if value == "all" 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
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
bmc-1.6.1 | app/filters/bmc/filter/by_key_value.rb |
bmc-1.6.0 | app/filters/bmc/filter/by_key_value.rb |