bitfields 0.13.0 → 0.14.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/Readme.md +1 -0
- data/lib/bitfields.rb +5 -0
- data/lib/bitfields/version.rb +1 -1
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: aa0272ff1f618bce120efefe15d9e33a355eda3ec2bf4d79035d59262f904360
|
4
|
+
data.tar.gz: 9707b7a856a7b6da7a801d337b85a51c031a52e6f665d84a78ba6d6a399acdde
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 35d06d5cbeb950fe38c05ab97920dc58774614793de3cfed986c04743d3d8330bb5a42f3ac46f82d3e0bd54ee23535c9f0b1e9956ecd364a06401f27db19921e
|
7
|
+
data.tar.gz: 9bb95fd7d86d30d0e60d6c3e1635f4b1f1723dba552f5f9ebda9fa374cffb40725e62b8187133951307a2cb769abe41d9ad8c0626bc62c489b851cc7967112a6
|
data/Readme.md
CHANGED
@@ -25,6 +25,7 @@ user.my_bits # => 3
|
|
25
25
|
- builds update sql `User.set_bitfield_sql(insane: true, sensible: false) == 'my_bits = (my_bits | 6) - 4'`
|
26
26
|
- **faster sql than any other bitfield lib** through combination of multiple bits into a single sql statement
|
27
27
|
- gives access to bits `User.bitfields[:my_bits][:sensible] # => 4`
|
28
|
+
- converts hash to bits `User.bitfield_bits(seller: true) # => 1`
|
28
29
|
|
29
30
|
Install
|
30
31
|
=======
|
data/lib/bitfields.rb
CHANGED
@@ -48,6 +48,11 @@ module Bitfields
|
|
48
48
|
add_bitfield_methods column, options
|
49
49
|
end
|
50
50
|
|
51
|
+
def bitfield_bits(values)
|
52
|
+
bits = bitfields.values.reduce({}, :merge)
|
53
|
+
values.sum { |bit, on| on ? bits.fetch(bit) : 0 }
|
54
|
+
end
|
55
|
+
|
51
56
|
def bitfield_column(bit_name)
|
52
57
|
found = bitfields.detect{|_, bits| bits.keys.include?(bit_name.to_sym) }
|
53
58
|
raise "Unknown bitfield #{bit_name}" unless found
|
data/lib/bitfields/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bitfields
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.14.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Grosser
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-01-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -123,8 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '0'
|
125
125
|
requirements: []
|
126
|
-
|
127
|
-
rubygems_version: 2.6.11
|
126
|
+
rubygems_version: 3.0.3
|
128
127
|
signing_key:
|
129
128
|
specification_version: 4
|
130
129
|
summary: Save migrations and columns by storing multiple booleans in a single integer
|