Class: BazaModels::Query::Not
- Inherits:
-
Object
- Object
- BazaModels::Query::Not
- Defined in:
- lib/baza_models/query/not.rb
Instance Method Summary collapse
-
#initialize(args) ⇒ Not
constructor
A new instance of Not.
- #not(args) ⇒ Object
Constructor Details
#initialize(args) ⇒ Not
Returns a new instance of Not.
2 3 4 5 6 7 |
# File 'lib/baza_models/query/not.rb', line 2 def initialize(args) @query = args.fetch(:query) @model = @query.instance_variable_get(:@model) @db = @query.instance_variable_get(:@db) @wheres = @query.instance_variable_get(:@wheres) end |
Instance Method Details
#not(args) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/baza_models/query/not.rb', line 9 def not(args) args.each do |key, value| if value.is_a?(Hash) value.each do |hash_key, hash_value| if hash_value.is_a?(Array) values = hash_value.map { |hash_value_i| "'#{@db.esc(hash_value_i)}'" }.join(",") @wheres << "`#{key}`.`#{hash_key}` NOT IN (#{values})" else @wheres << "`#{key}`.`#{hash_key}` != '#{@db.esc(hash_value)}'" end end elsif value.is_a?(Array) values = value.map { |value_i| "'#{@db.esc(value_i)}'" }.join(",") @wheres << "`#{@model.table_name}`.`#{key}` NOT IN (#{values})" else @wheres << "`#{@model.table_name}`.`#{key}` != '#{@db.esc(value)}'" end end @query end |