Class: Agilibox::SmallData::FilterStrategyByKeyValue
- Inherits:
-
FilterStrategy
- Object
- FilterStrategy
- Agilibox::SmallData::FilterStrategyByKeyValue
- Defined in:
- app/filters/agilibox/small_data/filter_strategy_by_key_value.rb
Direct Known Subclasses
FilterStrategyByDate, FilterStrategyByDateBegin, FilterStrategyByDateEnd, FilterStrategyByDateOrDatetimePeriod, FilterStrategyByKeyValues
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
Instance Method Summary collapse
- #apply(query, value) ⇒ Object
- #column_for(query) ⇒ Object
-
#initialize(key = nil) ⇒ FilterStrategyByKeyValue
constructor
A new instance of FilterStrategyByKeyValue.
Constructor Details
#initialize(key = nil) ⇒ FilterStrategyByKeyValue
Returns a new instance of FilterStrategyByKeyValue.
4 5 6 |
# File 'app/filters/agilibox/small_data/filter_strategy_by_key_value.rb', line 4 def initialize(key = nil) @key = key end |
Instance Attribute Details
#key ⇒ Object (readonly)
Returns the value of attribute key.
2 3 4 |
# File 'app/filters/agilibox/small_data/filter_strategy_by_key_value.rb', line 2 def key @key end |
Instance Method Details
#apply(query, value) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'app/filters/agilibox/small_data/filter_strategy_by_key_value.rb', line 8 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 |
#column_for(query) ⇒ Object
23 24 25 |
# File 'app/filters/agilibox/small_data/filter_strategy_by_key_value.rb', line 23 def column_for(query) key.is_a?(Symbol) ? "#{query.model.table_name}.#{key}" : key.to_s end |