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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c616e8677376c68d869fb5f49c9410227e4ff4e591a856c0730dfcc750d8139e
4
- data.tar.gz: eedd3a4aeb9df0022cea20110cfd0c0ce3fa2325acc2ae614c6dffeae7bdc9bd
3
+ metadata.gz: 624a3dadb88c65c2c87d3c4f3054b8e20d6b32d370df053e1d496ad1081fbb13
4
+ data.tar.gz: 3fe828937fc5bb799e6e250d8d96248708825262df7ad1e8ee61d80d4d000b04
5
5
  SHA512:
6
- metadata.gz: 8ba4eb0de8d2896976a54b6cfe4016a8e65cf81e94a27ec68205c426a2c0e513c113d28e57bc678b27c5693a6ced707ab3c8203783c41a06cc6e170fd3bb7fb7
7
- data.tar.gz: 53328c78180c6537332d43b1ed58163b96c22b5a893cb9004403a8db0aa2447bd9ce9986386462f338ffb1804f5aa8348777705fb776bf654873ba990198da70
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
@@ -9,3 +9,4 @@
9
9
  /tmp/
10
10
  /gemfiles/*.lock
11
11
  /gemfiles/.bundle
12
+ .ruby-version
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.6
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.rc1'
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
@@ -4,7 +4,7 @@ gemspec
4
4
 
5
5
  gem 'pry'
6
6
  # Don't update rubocop automatically because sometimes it fails test by breaking changes.
7
- gem 'rubocop', '0.86.0'
7
+ gem 'rubocop', '1.28.2'
8
8
  gem 'appraisal'
9
9
  gem 'rake'
10
10
  gem 'rspec'
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.roles?(:provider) #=> false
47
- post.roles?(:guest, :provider) #=> true
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.metadata = {
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', '>= 5.0'
31
+ spec.add_dependency 'activerecord', '>= 6.0'
30
32
  end
@@ -3,7 +3,7 @@
3
3
  source "https://rubygems.org"
4
4
 
5
5
  gem "pry"
6
- gem "rubocop", "0.86.0"
6
+ gem "rubocop", "1.28.2"
7
7
  gem "appraisal"
8
8
  gem "rake"
9
9
  gem "rspec"
@@ -3,11 +3,11 @@
3
3
  source "https://rubygems.org"
4
4
 
5
5
  gem "pry"
6
- gem "rubocop", "0.86.0"
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.rc1"
11
+ gem "activerecord", "~> 6.1.0"
12
12
 
13
13
  gemspec path: "../"
@@ -0,0 +1,13 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "pry"
6
+ gem "rubocop", "1.28.2"
7
+ gem "appraisal"
8
+ gem "rake"
9
+ gem "rspec"
10
+ gem "sqlite3"
11
+ gem "activerecord", "~> 7.0.0"
12
+
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
- def attribute?(attribute_name, *values)
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
- super
42
+ attribute?(attribute_name)
22
43
  end
23
44
  end
24
45
  end
@@ -6,6 +6,7 @@ module ActiveRecordBitmask
6
6
  # @param map [ActiveRecordBitmask::Map]
7
7
  # @param sub_type [ActiveModel::Type::Value]
8
8
  def initialize(_name, map, sub_type)
9
+ super()
9
10
  @map = map
10
11
  @sub_type = sub_type
11
12
  end
@@ -51,19 +51,26 @@ module ActiveRecordBitmask
51
51
  private
52
52
 
53
53
  def define_bitmask_attribute(attribute, map)
54
- # 2nd arguments is deleted in 6.1.0
55
- options = if ActiveRecord.gem_version >= Gem::Version.new('6.1.0.rc1')
56
- []
57
- else
58
- [:bitmask]
59
- end
60
-
61
- decorate_attribute_type(attribute, *options) do |subtype|
62
- ActiveRecordBitmask::BitmaskType.new(attribute, map, subtype)
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveRecordBitmask
4
- VERSION = '0.0.5'
4
+ VERSION = '1.0.0'
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.5
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: 2020-11-04 00:00:00.000000000 Z
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: '5.0'
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: '5.0'
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: '0'
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.2
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