bitfields 0.4.2 → 0.4.3
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/.travis.yml +17 -2
- data/Appraisals +4 -0
- data/Gemfile +1 -1
- data/Gemfile.lock +2 -2
- data/Readme.md +3 -1
- data/gemfiles/activerecord_2.3.gemfile +1 -1
- data/gemfiles/activerecord_2.3.gemfile.lock +2 -2
- data/gemfiles/activerecord_3.0.gemfile +1 -1
- data/gemfiles/activerecord_3.0.gemfile.lock +2 -2
- data/gemfiles/activerecord_3.1.gemfile +1 -1
- data/gemfiles/activerecord_3.1.gemfile.lock +2 -2
- data/gemfiles/activerecord_3.2.gemfile +1 -1
- data/gemfiles/activerecord_3.2.gemfile.lock +2 -2
- data/gemfiles/activerecord_4.0.gemfile +12 -0
- data/gemfiles/activerecord_4.0.gemfile.lock +59 -0
- data/lib/bitfields.rb +18 -4
- data/lib/bitfields/version.rb +1 -1
- data/spec/bitfields_spec.rb +15 -2
- metadata +7 -5
data/.travis.yml
CHANGED
@@ -1,4 +1,19 @@
|
|
1
1
|
rvm:
|
2
|
-
-
|
3
|
-
- 1.9.2
|
2
|
+
- 1.8.7
|
4
3
|
- 1.9.3
|
4
|
+
- 2.0.0
|
5
|
+
gemfile:
|
6
|
+
- gemfiles/activerecord_2.3.gemfile
|
7
|
+
- gemfiles/activerecord_3.0.gemfile
|
8
|
+
- gemfiles/activerecord_3.1.gemfile
|
9
|
+
- gemfiles/activerecord_3.2.gemfile
|
10
|
+
- gemfiles/activerecord_4.0.gemfile
|
11
|
+
matrix:
|
12
|
+
exclude:
|
13
|
+
- rvm: 1.8.7
|
14
|
+
gemfile: gemfiles/activerecord_4.0.gemfile
|
15
|
+
- rvm: 2.0.0
|
16
|
+
gemfile: gemfiles/activerecord_2.3.gemfile
|
17
|
+
- rvm: 2.0.0
|
18
|
+
gemfile: gemfiles/activerecord_3.0.gemfile
|
19
|
+
script: rake spec
|
data/Appraisals
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
data/Readme.md
CHANGED
@@ -13,7 +13,7 @@ user.stupid? == false
|
|
13
13
|
user.my_bits == 3
|
14
14
|
```
|
15
15
|
|
16
|
-
- records changes `user.
|
16
|
+
- records changes `user.changes == {:seller => [false, true]}`
|
17
17
|
- adds scopes `User.seller.stupid.first` (deactivate with `bitfield ..., :scopes => false`)
|
18
18
|
- builds sql `User.bitfield_sql(:insane => true, :stupid => false) == '(users.my_bits & 3) = 1'`
|
19
19
|
- builds index-using sql with `bitfield ... ,:query_mode => :in_list` and `User.bitfield_sql(:insane => true, :stupid => false) == 'users.my_bits IN (2, 3)'` (2 and 1+2), often slower than :bit_operator sql especially for high number of bits
|
@@ -59,6 +59,7 @@ TIPS
|
|
59
59
|
- bit_operator is faster in most cases, use :query_mode => :in_list sparingly
|
60
60
|
- Standard mysql integer is 4 byte -> 32 bitfields
|
61
61
|
- If you are lazy or bad at math you can also do `bitfields :bits, :foo, :bar, :baz`
|
62
|
+
- If you are want more readability and reduce clutter you can do `bitfields 2**0 => :foo, 2**1 => :bar, 2**32 => :baz`
|
62
63
|
|
63
64
|
Query-mode Benchmark
|
64
65
|
=========
|
@@ -90,6 +91,7 @@ Authors
|
|
90
91
|
- [Hellekin O. Wolf](https://github.com/hellekin)
|
91
92
|
- [John Wilkinson](https://github.com/jcwilk)
|
92
93
|
- [PeppyHeppy](https://github.com/peppyheppy)
|
94
|
+
- [kmcbride](https://github.com/kmcbride)
|
93
95
|
|
94
96
|
[Michael Grosser](http://grosser.it)<br/>
|
95
97
|
michael@grosser.it<br/>
|
@@ -0,0 +1,59 @@
|
|
1
|
+
PATH
|
2
|
+
remote: /Users/mgrosser/code/tools/bitfields
|
3
|
+
specs:
|
4
|
+
bitfields (0.4.2)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
activemodel (4.0.0.rc1)
|
10
|
+
activesupport (= 4.0.0.rc1)
|
11
|
+
builder (~> 3.1.0)
|
12
|
+
activerecord (4.0.0.rc1)
|
13
|
+
activemodel (= 4.0.0.rc1)
|
14
|
+
activerecord-deprecated_finders (~> 1.0.2)
|
15
|
+
activesupport (= 4.0.0.rc1)
|
16
|
+
arel (~> 4.0.0)
|
17
|
+
activerecord-deprecated_finders (1.0.2)
|
18
|
+
activesupport (4.0.0.rc1)
|
19
|
+
i18n (~> 0.6, >= 0.6.4)
|
20
|
+
minitest (~> 4.2)
|
21
|
+
multi_json (~> 1.3)
|
22
|
+
thread_safe (~> 0.1)
|
23
|
+
tzinfo (~> 0.3.37)
|
24
|
+
appraisal (0.5.2)
|
25
|
+
bundler
|
26
|
+
rake
|
27
|
+
arel (4.0.0)
|
28
|
+
atomic (1.1.9)
|
29
|
+
builder (3.1.4)
|
30
|
+
bump (0.4.1)
|
31
|
+
diff-lcs (1.2.4)
|
32
|
+
i18n (0.6.4)
|
33
|
+
minitest (4.7.4)
|
34
|
+
multi_json (1.7.3)
|
35
|
+
rake (10.0.4)
|
36
|
+
rspec (2.13.0)
|
37
|
+
rspec-core (~> 2.13.0)
|
38
|
+
rspec-expectations (~> 2.13.0)
|
39
|
+
rspec-mocks (~> 2.13.0)
|
40
|
+
rspec-core (2.13.1)
|
41
|
+
rspec-expectations (2.13.0)
|
42
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
43
|
+
rspec-mocks (2.13.1)
|
44
|
+
sqlite3 (1.3.7)
|
45
|
+
thread_safe (0.1.0)
|
46
|
+
atomic
|
47
|
+
tzinfo (0.3.37)
|
48
|
+
|
49
|
+
PLATFORMS
|
50
|
+
ruby
|
51
|
+
|
52
|
+
DEPENDENCIES
|
53
|
+
activerecord (~> 4.0.0.rc)
|
54
|
+
appraisal
|
55
|
+
bitfields!
|
56
|
+
bump
|
57
|
+
rake
|
58
|
+
rspec (~> 2)
|
59
|
+
sqlite3
|
data/lib/bitfields.rb
CHANGED
@@ -9,7 +9,7 @@ module Bitfields
|
|
9
9
|
def self.included(base)
|
10
10
|
class << base
|
11
11
|
attr_accessor :bitfields, :bitfield_options, :bitfield_args
|
12
|
-
|
12
|
+
|
13
13
|
# all the args passed into .bitfield so children can initialize from parents
|
14
14
|
def bitfield_args
|
15
15
|
@bitfield_args ||= []
|
@@ -38,9 +38,13 @@ module Bitfields
|
|
38
38
|
bitfields
|
39
39
|
end
|
40
40
|
|
41
|
+
def self.ar_3?
|
42
|
+
defined?(ActiveRecord::VERSION::MAJOR) and ActiveRecord::VERSION::MAJOR >= 3
|
43
|
+
end
|
44
|
+
|
41
45
|
# AR 3+ -> :scope, below :named_scope
|
42
46
|
def self.ar_scoping_method
|
43
|
-
if
|
47
|
+
if ar_3?
|
44
48
|
:scope
|
45
49
|
else
|
46
50
|
:named_scope
|
@@ -96,14 +100,24 @@ module Bitfields
|
|
96
100
|
|
97
101
|
if options[:scopes] != false
|
98
102
|
scoping_method = Bitfields.ar_scoping_method
|
99
|
-
send scoping_method, bit_name,
|
100
|
-
send scoping_method, "not_#{bit_name}",
|
103
|
+
send scoping_method, bit_name, bitfield_scope_options(bit_name => true)
|
104
|
+
send scoping_method, "not_#{bit_name}", bitfield_scope_options(bit_name => false)
|
101
105
|
end
|
102
106
|
end
|
103
107
|
|
104
108
|
include Bitfields::InstanceMethods
|
105
109
|
end
|
106
110
|
|
111
|
+
def bitfield_scope_options(bit_values)
|
112
|
+
sql = bitfield_sql(bit_values)
|
113
|
+
|
114
|
+
if Bitfields.ar_3?
|
115
|
+
lambda { where(sql) }
|
116
|
+
else
|
117
|
+
{:conditions => sql}
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
107
121
|
def bitfield_sql_by_column(column, bit_values, options={})
|
108
122
|
mode = options[:query_mode] || (bitfield_options[column][:query_mode] || :bit_operator)
|
109
123
|
case mode
|
data/lib/bitfields/version.rb
CHANGED
data/spec/bitfields_spec.rb
CHANGED
@@ -248,7 +248,13 @@ describe Bitfields do
|
|
248
248
|
u1 = MultiBitUser.create!(:seller => true, :one => true)
|
249
249
|
u2 = MultiBitUser.create!(:seller => true, :one => false)
|
250
250
|
u3 = MultiBitUser.create!(:seller => false, :one => false)
|
251
|
-
|
251
|
+
conditions = MultiBitUser.bitfield_sql({:seller => true, :one => false}, :query_mode => :in_list)
|
252
|
+
result = if Bitfields.ar_3?
|
253
|
+
MultiBitUser.where(conditions)
|
254
|
+
else
|
255
|
+
MultiBitUser.all(:conditions => conditions)
|
256
|
+
end
|
257
|
+
result.should == [u2]
|
252
258
|
end
|
253
259
|
|
254
260
|
describe 'with bit operator mode' do
|
@@ -264,7 +270,14 @@ describe Bitfields do
|
|
264
270
|
u1 = BitOperatorMode.create!(:seller => true, :insane => true)
|
265
271
|
u2 = BitOperatorMode.create!(:seller => true, :insane => false)
|
266
272
|
u3 = BitOperatorMode.create!(:seller => false, :insane => false)
|
267
|
-
|
273
|
+
|
274
|
+
conditions = MultiBitUser.bitfield_sql(:seller => true, :insane => false)
|
275
|
+
result = if Bitfields.ar_3?
|
276
|
+
BitOperatorMode.where(conditions)
|
277
|
+
else
|
278
|
+
BitOperatorMode.all(:conditions => conditions)
|
279
|
+
end
|
280
|
+
result.should == [u2]
|
268
281
|
end
|
269
282
|
end
|
270
283
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bitfields
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-05-14 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description:
|
15
15
|
email: michael@grosser.it
|
@@ -33,6 +33,8 @@ files:
|
|
33
33
|
- gemfiles/activerecord_3.1.gemfile.lock
|
34
34
|
- gemfiles/activerecord_3.2.gemfile
|
35
35
|
- gemfiles/activerecord_3.2.gemfile.lock
|
36
|
+
- gemfiles/activerecord_4.0.gemfile
|
37
|
+
- gemfiles/activerecord_4.0.gemfile.lock
|
36
38
|
- lib/bitfields.rb
|
37
39
|
- lib/bitfields/rspec.rb
|
38
40
|
- lib/bitfields/version.rb
|
@@ -54,7 +56,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
54
56
|
version: '0'
|
55
57
|
segments:
|
56
58
|
- 0
|
57
|
-
hash:
|
59
|
+
hash: 950427918472941761
|
58
60
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
59
61
|
none: false
|
60
62
|
requirements:
|
@@ -63,10 +65,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
63
65
|
version: '0'
|
64
66
|
segments:
|
65
67
|
- 0
|
66
|
-
hash:
|
68
|
+
hash: 950427918472941761
|
67
69
|
requirements: []
|
68
70
|
rubyforge_project:
|
69
|
-
rubygems_version: 1.8.
|
71
|
+
rubygems_version: 1.8.25
|
70
72
|
signing_key:
|
71
73
|
specification_version: 3
|
72
74
|
summary: Save migrations and columns by storing multiple booleans in a single integer
|