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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f0836338456ad6155feff23e641e6f6b991ba9a670763b2c09c9ab2a3d243797
4
- data.tar.gz: 0210e6445e4ac868fe4e41d3473b4f8fdb17ff0202e2058ad89845023e939c11
3
+ metadata.gz: c280de0aa76c1faf1a0eedaa01e79e1cd573409e0fe213e0ec2ec2a386fd6905
4
+ data.tar.gz: a12217033318fbcc0de0fa377fb008d873efb4f715229df96d9f311f86be3d9b
5
5
  SHA512:
6
- metadata.gz: 040e8da0c1ef2cdc42687c5ae66eb7d379d25a29d7b13c29877a27dd8c834075542b4757a2950e57b8cb945ebe37fa2a5ad2ddc36653eb2434ada7e088837487
7
- data.tar.gz: 8373e9a4903dfab97a8ec21052192e99f4813ff99257e362c025427f1de3b97228565f2b35df65edb35ef39f0c3ab28fe917ec43c49ceb877c4601ec1b3fc34d
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
- #### `with_rules`
58
+ #### `with_roles`
59
59
 
60
- #### `with_any_rules`
60
+ #### `with_any_roles`
61
61
 
62
- #### `without_rules`
62
+ #### `without_roles`
63
63
 
64
- #### `with_exact_rules`
64
+ #### `with_exact_roles`
65
65
 
66
- #### `no_rules`
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/pixiv/active_record_bitmask'
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveRecordBitmask
4
- VERSION = '0.0.1'
4
+ VERSION = '0.0.2'
5
5
  end
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.1
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-08 00:00:00.000000000 Z
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/pixiv/active_record_bitmask
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: []