Sha256: 7efe188bbca35a7cca2319a4585ff69f32a1412a3d120fcf07556362c0740ab0
Contents?: true
Size: 581 Bytes
Versions: 9
Compression:
Stored size: 581 Bytes
Contents
class BMC::Filter::ByKeyValue 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
9 entries across 9 versions & 1 rubygems