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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: fa18acfa732a68288db8c56fc05ccfae55530be9
4
- data.tar.gz: 1a23e528932a1e8d1873ec8ec9a707a6c3dc000d
2
+ SHA256:
3
+ metadata.gz: aa0272ff1f618bce120efefe15d9e33a355eda3ec2bf4d79035d59262f904360
4
+ data.tar.gz: 9707b7a856a7b6da7a801d337b85a51c031a52e6f665d84a78ba6d6a399acdde
5
5
  SHA512:
6
- metadata.gz: 0c14625d4af510f6789978ad7b872cb4b300e08efeb8af4d03b235086afb5dcce677f03a242f051987011f9b38750416b6e1fd00d934ba9a538acd97c275ae7c
7
- data.tar.gz: b7f9579b08062e2e140272f8942c4a659a9a22e2610d3987df6211c4b0c37d2d10cc469c2de56cdc6d99ef8eeb078e70ca013d967adb5518b2e3caa9de3c118f
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
  =======
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Bitfields
2
- Version = VERSION = "0.13.0"
2
+ Version = VERSION = "0.14.0"
3
3
  end
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.13.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: 2019-11-23 00:00:00.000000000 Z
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
- rubyforge_project:
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