active_record_bitmask 0.0.5 → 0.0.6
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/.travis.yml +18 -3
- data/Appraisals +4 -0
- data/CHANGELOG.md +5 -0
- data/README.md +2 -2
- data/gemfiles/7.0_stable.gemfile +13 -0
- data/lib/active_record_bitmask/attribute_methods/query.rb +23 -2
- data/lib/active_record_bitmask/model.rb +15 -9
- data/lib/active_record_bitmask/version.rb +1 -1
- metadata +8 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 92ef09e4ac0ca5c2da0db1869dc52776f5d990292e9c921bf02e364f1535925c
|
4
|
+
data.tar.gz: 5e48672686d4d15b10f547a2fccd0c017799dd259bf36f2d1184da9261bce2c8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 99696c27cf5fdcfede8e64be3791da418276f6dbd7b1edcb960b5dec585aa14587e82bf686e635d60cbccd0fbc4ab0c88e39150a24504c98e974b07048a55825
|
7
|
+
data.tar.gz: d3dfbe52f15833aada4cbe70559f93c3493511872a1af6f024c1f54d77c8697dab77f396debed19be074014bbe3e077442cfadb2e0a2da414a0126eecf89c07c
|
data/.travis.yml
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
sudo: false
|
2
2
|
language: ruby
|
3
3
|
rvm:
|
4
|
-
- 2.5.
|
5
|
-
- 2.6.
|
6
|
-
- 2.7.
|
4
|
+
- 2.5.8
|
5
|
+
- 2.6.6
|
6
|
+
- 2.7.2
|
7
|
+
- 3.0.0
|
7
8
|
before_install: gem install bundler
|
8
9
|
gemfile:
|
9
10
|
- gemfiles/5.0_stable.gemfile
|
@@ -11,6 +12,20 @@ gemfile:
|
|
11
12
|
- gemfiles/5.2_stable.gemfile
|
12
13
|
- gemfiles/6.0_stable.gemfile
|
13
14
|
- gemfiles/6.1_stable.gemfile
|
15
|
+
matrix:
|
16
|
+
exclude:
|
17
|
+
- rvm: 2.5.8
|
18
|
+
gemfile: gemfiles/6.1_stable.gemfile
|
19
|
+
- rvm: 2.6.6
|
20
|
+
gemfile: gemfiles/6.1_stable.gemfile
|
21
|
+
- rvm: 2.7.2
|
22
|
+
gemfile: gemfiles/6.1_stable.gemfile
|
23
|
+
- rvm: 3.0.0
|
24
|
+
gemfile: gemfiles/5.0_stable.gemfile
|
25
|
+
- rvm: 3.0.0
|
26
|
+
gemfile: gemfiles/5.1_stable.gemfile
|
27
|
+
- rvm: 3.0.0
|
28
|
+
gemfile: gemfiles/5.2_stable.gemfile
|
14
29
|
script:
|
15
30
|
- bundle exec rspec
|
16
31
|
- bundle exec rubocop
|
data/Appraisals
CHANGED
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -43,8 +43,8 @@ You can check bitmask
|
|
43
43
|
|
44
44
|
```ruby
|
45
45
|
post = Post.create(roles: [:provider, :guest])
|
46
|
-
post.
|
47
|
-
post.
|
46
|
+
post.roles_bitmask?(:provider) #=> false
|
47
|
+
post.roles_bitmask?(:guest, :provider) #=> true
|
48
48
|
```
|
49
49
|
|
50
50
|
You can get the definition of bitmask
|
@@ -1,15 +1,36 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'active_record'
|
4
|
+
require 'active_support/concern'
|
5
|
+
|
3
6
|
module ActiveRecordBitmask
|
4
7
|
module AttributeMethods
|
5
8
|
module Query
|
9
|
+
extend ActiveSupport::Concern
|
10
|
+
|
11
|
+
included do
|
12
|
+
attribute_method_suffix('_bitmask?')
|
13
|
+
end
|
14
|
+
|
6
15
|
private
|
7
16
|
|
8
17
|
def bitmask_attribute?(attribute_name)
|
9
18
|
self.class.bitmasks.key?(attribute_name.to_sym)
|
10
19
|
end
|
11
20
|
|
12
|
-
|
21
|
+
if ActiveRecord.gem_version < Gem::Version.create('7.0.0.alpha1')
|
22
|
+
# In Rails 7.0.0, calling attribute? with arguments is not working.
|
23
|
+
def attribute?(attribute_name, *values)
|
24
|
+
if bitmask_attribute?(attribute_name) && values.present?
|
25
|
+
ActiveSupport::Deprecation.warn("`#{attribute_name}?(*args)` is deprecated and will be removed in next major version. Call `#{attribute_name}_bitmask?(*args)` instead.")
|
26
|
+
attribute_bitmask?(attribute_name, *values)
|
27
|
+
else
|
28
|
+
super
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def attribute_bitmask?(attribute_name, *values)
|
13
34
|
if bitmask_attribute?(attribute_name) && values.present?
|
14
35
|
# assert bitmask values
|
15
36
|
map = self.class.bitmask_for(attribute_name)
|
@@ -18,7 +39,7 @@ module ActiveRecordBitmask
|
|
18
39
|
|
19
40
|
(current_value & expected_value) == expected_value
|
20
41
|
else
|
21
|
-
|
42
|
+
attribute?(attribute_name)
|
22
43
|
end
|
23
44
|
end
|
24
45
|
end
|
@@ -51,15 +51,21 @@ module ActiveRecordBitmask
|
|
51
51
|
private
|
52
52
|
|
53
53
|
def define_bitmask_attribute(attribute, map)
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
54
|
+
if ActiveRecord.gem_version >= Gem::Version.new('7.0.0.alpha1')
|
55
|
+
# Greater than or equal to 7.0.0
|
56
|
+
attribute(attribute) do |subtype|
|
57
|
+
ActiveRecordBitmask::BitmaskType.new(attribute, map, subtype)
|
58
|
+
end
|
59
|
+
elsif ActiveRecord.gem_version >= Gem::Version.new('6.1.0')
|
60
|
+
# Equal to 6.1.0
|
61
|
+
decorate_attribute_type(attribute) do |subtype|
|
62
|
+
ActiveRecordBitmask::BitmaskType.new(attribute, map, subtype)
|
63
|
+
end
|
64
|
+
else
|
65
|
+
# Less than 6.1.0
|
66
|
+
decorate_attribute_type(attribute, :bitmask) do |subtype|
|
67
|
+
ActiveRecordBitmask::BitmaskType.new(attribute, map, subtype)
|
68
|
+
end
|
63
69
|
end
|
64
70
|
end
|
65
71
|
|
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.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- alpaca-tc
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-09-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -24,7 +24,7 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '5.0'
|
27
|
-
description:
|
27
|
+
description:
|
28
28
|
email:
|
29
29
|
- alpaca-tc@alpaca.tc
|
30
30
|
executables: []
|
@@ -46,6 +46,7 @@ files:
|
|
46
46
|
- gemfiles/5.2_stable.gemfile
|
47
47
|
- gemfiles/6.0_stable.gemfile
|
48
48
|
- gemfiles/6.1_stable.gemfile
|
49
|
+
- gemfiles/7.0_stable.gemfile
|
49
50
|
- lib/active_record_bitmask.rb
|
50
51
|
- lib/active_record_bitmask/attribute_methods.rb
|
51
52
|
- lib/active_record_bitmask/attribute_methods/query.rb
|
@@ -61,7 +62,7 @@ metadata:
|
|
61
62
|
changelog_uri: https://github.com/alpaca-tc/active_record_bitmask/blob/master/CHANGELOG.md
|
62
63
|
source_code_uri: https://github.com/alpaca-tc/active_record_bitmask/
|
63
64
|
bug_tracker_uri: https://github.com/alpaca-tc/active_record_bitmask/issues
|
64
|
-
post_install_message:
|
65
|
+
post_install_message:
|
65
66
|
rdoc_options: []
|
66
67
|
require_paths:
|
67
68
|
- lib
|
@@ -76,8 +77,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
76
77
|
- !ruby/object:Gem::Version
|
77
78
|
version: '0'
|
78
79
|
requirements: []
|
79
|
-
rubygems_version: 3.1.
|
80
|
-
signing_key:
|
80
|
+
rubygems_version: 3.1.6
|
81
|
+
signing_key:
|
81
82
|
specification_version: 4
|
82
83
|
summary: Simple bitmask attribute support for ActiveRecord
|
83
84
|
test_files: []
|