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 +24 -5
- data/lib/bitswitch/version.rb +1 -1
- metadata +1 -1
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
|
-
|
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
|
-
#
|
185
|
-
|
186
|
-
|
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
|
-
#
|
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
|
|
data/lib/bitswitch/version.rb
CHANGED