active_record_bitmask 0.0.1 → 0.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.
- checksums.yaml +4 -4
- data/README.md +5 -5
- data/active_record_bitmask.gemspec +2 -1
- data/lib/active_record_bitmask/map.rb +10 -0
- data/lib/active_record_bitmask/version.rb +1 -1
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c280de0aa76c1faf1a0eedaa01e79e1cd573409e0fe213e0ec2ec2a386fd6905
|
4
|
+
data.tar.gz: a12217033318fbcc0de0fa377fb008d873efb4f715229df96d9f311f86be3d9b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4e2b1d0f778ef4cfb1ebd4ee438b5ea3777b86dcea8f25bfd686a1ce06439d5a62778376f624dd4cd036f6aa2fc083226458b0632867a2e5d661c0bf68afb266
|
7
|
+
data.tar.gz: 39be7a07fca3f6ab7b4e3e3c806e4f63aba832451ddb2acfd9ef0710a6951499365ae0e9b6f72322d7e65cf770797646fa36de01effa6657abd521cf4dc6a60f
|
data/README.md
CHANGED
@@ -55,15 +55,15 @@ map.values #=> [1, 2, 4]
|
|
55
55
|
|
56
56
|
### Scopes
|
57
57
|
|
58
|
-
#### `
|
58
|
+
#### `with_roles`
|
59
59
|
|
60
|
-
#### `
|
60
|
+
#### `with_any_roles`
|
61
61
|
|
62
|
-
#### `
|
62
|
+
#### `without_roles`
|
63
63
|
|
64
|
-
#### `
|
64
|
+
#### `with_exact_roles`
|
65
65
|
|
66
|
-
#### `
|
66
|
+
#### `no_roles`
|
67
67
|
|
68
68
|
## Development
|
69
69
|
|
@@ -9,9 +9,10 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.version = ActiveRecordBitmask::VERSION
|
10
10
|
spec.authors = ['alpaca-tc']
|
11
11
|
spec.email = ['alpaca-tc@alpaca.tc']
|
12
|
+
spec.licenses = ['MIT']
|
12
13
|
|
13
14
|
spec.summary = 'Simple bitmask attribute support for ActiveRecord'
|
14
|
-
spec.homepage = 'https://github.com/
|
15
|
+
spec.homepage = 'https://github.com/alpaca-tc/active_record_bitmask'
|
15
16
|
|
16
17
|
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
17
18
|
f.match(%r{^(test|spec|features)/})
|
@@ -2,6 +2,9 @@
|
|
2
2
|
|
3
3
|
module ActiveRecordBitmask
|
4
4
|
class Map
|
5
|
+
# Default blank values for checkbox
|
6
|
+
BLANK_VALUES = [:'', :'0'].freeze
|
7
|
+
|
5
8
|
attr_reader :mapping
|
6
9
|
|
7
10
|
# @param keys [Array<#to_sym>]
|
@@ -52,6 +55,7 @@ module ActiveRecordBitmask
|
|
52
55
|
# @return [Integer]
|
53
56
|
def attributes_to_bitmask(attributes)
|
54
57
|
attributes = [attributes].compact unless attributes.respond_to?(:inject)
|
58
|
+
attributes = reject_blank_attributes(attributes)
|
55
59
|
|
56
60
|
attributes.inject(0) do |bitmask, key|
|
57
61
|
key = key.to_sym if key.respond_to?(:to_sym)
|
@@ -72,6 +76,12 @@ module ActiveRecordBitmask
|
|
72
76
|
|
73
77
|
private
|
74
78
|
|
79
|
+
def reject_blank_attributes(attributes)
|
80
|
+
attributes.reject do |value|
|
81
|
+
BLANK_VALUES.include?(value.to_s.to_sym)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
75
85
|
def attributes_to_mapping(keys)
|
76
86
|
keys.each_with_index.each_with_object({}) do |(value, index), hash|
|
77
87
|
hash[value.to_sym] = 0b1 << index
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_record_bitmask
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- alpaca-tc
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-01-
|
11
|
+
date: 2020-01-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -88,8 +88,9 @@ files:
|
|
88
88
|
- lib/active_record_bitmask/map.rb
|
89
89
|
- lib/active_record_bitmask/model.rb
|
90
90
|
- lib/active_record_bitmask/version.rb
|
91
|
-
homepage: https://github.com/
|
92
|
-
licenses:
|
91
|
+
homepage: https://github.com/alpaca-tc/active_record_bitmask
|
92
|
+
licenses:
|
93
|
+
- MIT
|
93
94
|
metadata: {}
|
94
95
|
post_install_message:
|
95
96
|
rdoc_options: []
|