bitswitch 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/bitswitch.rb CHANGED
@@ -179,14 +179,33 @@ if defined? ActiveRecord::Base
179
179
  raise KellyLSB::BitSwitch::Error, "Missing arguments!" if args.empty?
180
180
  bits = hash.invert
181
181
 
182
- query = self
182
+ # Type of condition
183
+ if args.first.is_a?(String) && ['AND', 'OR'].include?(args.first.upcase)
184
+ delimiter = args.shift
185
+ else
186
+ delimiter = 'AND'
187
+ end
183
188
 
184
- # Perform conditions
185
- args.each do |slug|
186
- query = query.where("POW(2, ?) & `#{self.table_name}`.`#{column}` > 0", bits[slug.to_s])
189
+ # Empty conditions
190
+ conditions = Array.new
191
+
192
+ # Build conditions
193
+ if args.first.is_a?(Hash)
194
+ args.first.each do |slug,tf|
195
+ bit = bits[slug.to_s]
196
+ conditions << "POW(2, #{bit}) & `#{self.table_name}`.`#{column}`" + (tf ? ' > 0' : ' <= 0')
197
+ end
198
+ else
199
+ args.each do |slug|
200
+ bit = bits[slug.to_s]
201
+ conditions << "POW(2, #{bit}) & `#{self.table_name}`.`#{column}` > 0"
202
+ end
187
203
  end
188
204
 
189
- # Return results
205
+ # Run add query
206
+ return self.where(conditions.join(" #{delimiter} ")) unless conditions.empty?
207
+
208
+ # Return update query
190
209
  return query
191
210
  end
192
211
 
@@ -1,3 +1,3 @@
1
1
  module Bitswitch
2
- VERSION = "1.0.1"
2
+ VERSION = "1.0.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bitswitch
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: