active_record_bitmask 0.0.5 → 1.0.0
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/.github/workflows/ci.yml +54 -0
- data/.gitignore +1 -0
- data/.rubocop.yml +14 -1
- data/Appraisals +5 -14
- data/CHANGELOG.md +14 -0
- data/Gemfile +1 -1
- data/README.md +2 -2
- data/active_record_bitmask.gemspec +4 -2
- data/gemfiles/6.0_stable.gemfile +1 -1
- data/gemfiles/6.1_stable.gemfile +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/bitmask_type.rb +1 -0
- data/lib/active_record_bitmask/model.rb +17 -9
- data/lib/active_record_bitmask/version.rb +1 -1
- metadata +8 -7
- data/.travis.yml +0 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 624a3dadb88c65c2c87d3c4f3054b8e20d6b32d370df053e1d496ad1081fbb13
|
4
|
+
data.tar.gz: 3fe828937fc5bb799e6e250d8d96248708825262df7ad1e8ee61d80d4d000b04
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c914453a693e29f98eb756956a33ddc2f2373cce35820863a1827531658a83bc902b5c8344e0561b1db7069f57da4e3500ce323450c7c9eb18e7410601d96817
|
7
|
+
data.tar.gz: 24d72c973b8ed34f8017caa999b132d81a105fb679844054588196e4ae3b9545e93c8ba55de4fe1177df8632460daed6a4d10fe71aca8b100ca4afb638ac1d35
|
@@ -0,0 +1,54 @@
|
|
1
|
+
name: Ruby
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches: ["main"]
|
6
|
+
pull_request:
|
7
|
+
branches: ["main"]
|
8
|
+
|
9
|
+
permissions:
|
10
|
+
contents: read
|
11
|
+
|
12
|
+
jobs:
|
13
|
+
rubocop:
|
14
|
+
runs-on: ubuntu-latest
|
15
|
+
strategy:
|
16
|
+
matrix:
|
17
|
+
ruby-version: ['3.1', '3.2']
|
18
|
+
|
19
|
+
steps:
|
20
|
+
- uses: actions/checkout@v3
|
21
|
+
- name: Set up Ruby
|
22
|
+
uses: ruby/setup-ruby@v1
|
23
|
+
with:
|
24
|
+
ruby-version: ${{ matrix.ruby-version }}
|
25
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
26
|
+
- name: Run rubocop
|
27
|
+
run: bundle exec rubocop
|
28
|
+
|
29
|
+
test:
|
30
|
+
runs-on: ubuntu-latest
|
31
|
+
strategy:
|
32
|
+
matrix:
|
33
|
+
gemfile: ['6.0_stable', '6.1_stable', '7.0_stable']
|
34
|
+
ruby-version: ['2.5', '2.6', '2.7', '3.0', '3.1', '3.2']
|
35
|
+
exclude:
|
36
|
+
- ruby-version: '3.2'
|
37
|
+
gemfile: '6.0_stable'
|
38
|
+
- ruby-version: '3.1'
|
39
|
+
gemfile: '6.0_stable'
|
40
|
+
- ruby-version: '2.5'
|
41
|
+
gemfile: '7.0_stable'
|
42
|
+
- ruby-version: '2.6'
|
43
|
+
gemfile: '7.0_stable'
|
44
|
+
env:
|
45
|
+
BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/${{ matrix.gemfile }}.gemfile
|
46
|
+
steps:
|
47
|
+
- uses: actions/checkout@v3
|
48
|
+
- name: Set up Ruby
|
49
|
+
uses: ruby/setup-ruby@v1
|
50
|
+
with:
|
51
|
+
ruby-version: ${{ matrix.ruby-version }}
|
52
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
53
|
+
- name: Run tests
|
54
|
+
run: bundle exec rspec
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
@@ -1,9 +1,19 @@
|
|
1
1
|
AllCops:
|
2
|
+
NewCops: enable
|
3
|
+
SuggestExtensions: false
|
4
|
+
Include:
|
5
|
+
- 'Gemfile'
|
6
|
+
- 'Appraisals'
|
7
|
+
- 'Rakefile'
|
8
|
+
- 'gemfiles/**/*'
|
9
|
+
- 'lib/**/*'
|
10
|
+
- 'spec/**/*'
|
2
11
|
Exclude:
|
3
12
|
- '.bundle/**/*'
|
13
|
+
- 'vendor/**/*'
|
4
14
|
- 'gemfiles/**/*'
|
5
15
|
- Gemfile
|
6
|
-
TargetRubyVersion: 2.
|
16
|
+
TargetRubyVersion: 2.5
|
7
17
|
DisplayCopNames: true
|
8
18
|
|
9
19
|
Bundler:
|
@@ -87,3 +97,6 @@ Metrics/PerceivedComplexity:
|
|
87
97
|
Lint/UselessAccessModifier:
|
88
98
|
ContextCreatingMethods:
|
89
99
|
- concerning
|
100
|
+
|
101
|
+
Lint/EmptyBlock:
|
102
|
+
Enabled: false
|
data/Appraisals
CHANGED
@@ -1,22 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
appraise '5.0-stable' do
|
4
|
-
gem 'activerecord', '~> 5.0.0'
|
5
|
-
gem 'sqlite3', '~> 1.3.6'
|
6
|
-
end
|
7
|
-
|
8
|
-
appraise '5.1-stable' do
|
9
|
-
gem 'activerecord', '~> 5.1.0'
|
10
|
-
end
|
11
|
-
|
12
|
-
appraise '5.2-stable' do
|
13
|
-
gem 'activerecord', '~> 5.2.0'
|
14
|
-
end
|
15
|
-
|
16
3
|
appraise '6.0-stable' do
|
17
4
|
gem 'activerecord', '~> 6.0.0'
|
18
5
|
end
|
19
6
|
|
20
7
|
appraise '6.1-stable' do
|
21
|
-
gem 'activerecord', '~> 6.1.0
|
8
|
+
gem 'activerecord', '~> 6.1.0'
|
9
|
+
end
|
10
|
+
|
11
|
+
appraise '7.0-stable' do
|
12
|
+
gem 'activerecord', '~> 7.0.0'
|
22
13
|
end
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,17 @@
|
|
1
|
+
## Next Version
|
2
|
+
|
3
|
+
## 1.0.0
|
4
|
+
|
5
|
+
* **Breaking Changes** Rails 5.0, 5.1 and 5.2 are no longer supported. #23
|
6
|
+
* Changed the version of rails specified in appraisal to stable version. #20
|
7
|
+
* Migrate travis.ci to Github Actions #22
|
8
|
+
* Support ruby 3.2 #24
|
9
|
+
|
10
|
+
## 0.0.6
|
11
|
+
|
12
|
+
* Deprecate `#attribute?(*args)` in favor of `#attribute_bitmask?(*args)`. #17
|
13
|
+
* Support Rails 7.0.0.alpha1 #18
|
14
|
+
|
1
15
|
## 0.0.5
|
2
16
|
|
3
17
|
* Support Rails 6.1.0 #14
|
data/Gemfile
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
|
@@ -14,7 +14,9 @@ Gem::Specification.new do |spec|
|
|
14
14
|
spec.summary = 'Simple bitmask attribute support for ActiveRecord'
|
15
15
|
spec.homepage = 'https://github.com/alpaca-tc/active_record_bitmask'
|
16
16
|
|
17
|
-
spec.
|
17
|
+
spec.required_ruby_version = '>= 2.5.0'
|
18
|
+
|
19
|
+
spec.metadata = {
|
18
20
|
'homepage_uri' => 'https://github.com/alpaca-tc/active_record_bitmask',
|
19
21
|
'changelog_uri' => 'https://github.com/alpaca-tc/active_record_bitmask/blob/master/CHANGELOG.md',
|
20
22
|
'source_code_uri' => 'https://github.com/alpaca-tc/active_record_bitmask/',
|
@@ -26,5 +28,5 @@ Gem::Specification.new do |spec|
|
|
26
28
|
end
|
27
29
|
spec.require_paths = ['lib']
|
28
30
|
|
29
|
-
spec.add_dependency 'activerecord', '>=
|
31
|
+
spec.add_dependency 'activerecord', '>= 6.0'
|
30
32
|
end
|
data/gemfiles/6.0_stable.gemfile
CHANGED
data/gemfiles/6.1_stable.gemfile
CHANGED
@@ -3,11 +3,11 @@
|
|
3
3
|
source "https://rubygems.org"
|
4
4
|
|
5
5
|
gem "pry"
|
6
|
-
gem "rubocop", "
|
6
|
+
gem "rubocop", "1.28.2"
|
7
7
|
gem "appraisal"
|
8
8
|
gem "rake"
|
9
9
|
gem "rspec"
|
10
10
|
gem "sqlite3"
|
11
|
-
gem "activerecord", "~> 6.1.0
|
11
|
+
gem "activerecord", "~> 6.1.0"
|
12
12
|
|
13
13
|
gemspec path: "../"
|
@@ -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,19 +51,26 @@ 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
|
|
66
72
|
# rubocop:disable Metrics/CyclomaticComplexity
|
73
|
+
# rubocop:disable Metrics/PerceivedComplexity
|
67
74
|
def define_bitmask_scopes(attribute)
|
68
75
|
blank = [0, nil].freeze
|
69
76
|
|
@@ -121,6 +128,7 @@ module ActiveRecordBitmask
|
|
121
128
|
}
|
122
129
|
end
|
123
130
|
# rubocop:enable Metrics/CyclomaticComplexity
|
131
|
+
# rubocop:enable Metrics/PerceivedComplexity
|
124
132
|
end
|
125
133
|
end
|
126
134
|
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
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- alpaca-tc
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-01-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '6.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '6.0'
|
27
27
|
description:
|
28
28
|
email:
|
29
29
|
- alpaca-tc@alpaca.tc
|
@@ -31,10 +31,10 @@ executables: []
|
|
31
31
|
extensions: []
|
32
32
|
extra_rdoc_files: []
|
33
33
|
files:
|
34
|
+
- ".github/workflows/ci.yml"
|
34
35
|
- ".gitignore"
|
35
36
|
- ".rspec"
|
36
37
|
- ".rubocop.yml"
|
37
|
-
- ".travis.yml"
|
38
38
|
- Appraisals
|
39
39
|
- CHANGELOG.md
|
40
40
|
- Gemfile
|
@@ -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
|
@@ -69,14 +70,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
69
70
|
requirements:
|
70
71
|
- - ">="
|
71
72
|
- !ruby/object:Gem::Version
|
72
|
-
version:
|
73
|
+
version: 2.5.0
|
73
74
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
75
|
requirements:
|
75
76
|
- - ">="
|
76
77
|
- !ruby/object:Gem::Version
|
77
78
|
version: '0'
|
78
79
|
requirements: []
|
79
|
-
rubygems_version: 3.1
|
80
|
+
rubygems_version: 3.4.1
|
80
81
|
signing_key:
|
81
82
|
specification_version: 4
|
82
83
|
summary: Simple bitmask attribute support for ActiveRecord
|
data/.travis.yml
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
sudo: false
|
2
|
-
language: ruby
|
3
|
-
rvm:
|
4
|
-
- 2.5.7
|
5
|
-
- 2.6.5
|
6
|
-
- 2.7.0
|
7
|
-
before_install: gem install bundler
|
8
|
-
gemfile:
|
9
|
-
- gemfiles/5.0_stable.gemfile
|
10
|
-
- gemfiles/5.1_stable.gemfile
|
11
|
-
- gemfiles/5.2_stable.gemfile
|
12
|
-
- gemfiles/6.0_stable.gemfile
|
13
|
-
- gemfiles/6.1_stable.gemfile
|
14
|
-
script:
|
15
|
-
- bundle exec rspec
|
16
|
-
- bundle exec rubocop
|