active_record_bitmask 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c616e8677376c68d869fb5f49c9410227e4ff4e591a856c0730dfcc750d8139e
4
- data.tar.gz: eedd3a4aeb9df0022cea20110cfd0c0ce3fa2325acc2ae614c6dffeae7bdc9bd
3
+ metadata.gz: 92ef09e4ac0ca5c2da0db1869dc52776f5d990292e9c921bf02e364f1535925c
4
+ data.tar.gz: 5e48672686d4d15b10f547a2fccd0c017799dd259bf36f2d1184da9261bce2c8
5
5
  SHA512:
6
- metadata.gz: 8ba4eb0de8d2896976a54b6cfe4016a8e65cf81e94a27ec68205c426a2c0e513c113d28e57bc678b27c5693a6ced707ab3c8203783c41a06cc6e170fd3bb7fb7
7
- data.tar.gz: 53328c78180c6537332d43b1ed58163b96c22b5a893cb9004403a8db0aa2447bd9ce9986386462f338ffb1804f5aa8348777705fb776bf654873ba990198da70
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.7
5
- - 2.6.5
6
- - 2.7.0
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
@@ -20,3 +20,7 @@ end
20
20
  appraise '6.1-stable' do
21
21
  gem 'activerecord', '~> 6.1.0.rc1'
22
22
  end
23
+
24
+ appraise '7.0-stable' do
25
+ gem 'activerecord', '7.0.0.alpha2'
26
+ end
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 0.0.6
2
+
3
+ * Deprecate `#attribute?(*args)` in favor of `#attribute_bitmask?(*args)`. #17
4
+ * Support Rails 7.0.0.alpha1 #18
5
+
1
6
  ## 0.0.5
2
7
 
3
8
  * Support Rails 6.1.0 #14
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
@@ -0,0 +1,13 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "pry"
6
+ gem "rubocop", "0.86.0"
7
+ gem "appraisal"
8
+ gem "rake"
9
+ gem "rspec"
10
+ gem "sqlite3"
11
+ gem "activerecord", "7.0.0.alpha2"
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
@@ -51,15 +51,21 @@ 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
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveRecordBitmask
4
- VERSION = '0.0.5'
4
+ VERSION = '0.0.6'
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: 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: 2020-11-04 00:00:00.000000000 Z
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.2
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: []