active_flag 1.5.2 → 2.0.0

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: 2138875041460aa14daf08205e785d254a98de7480493ba02384b0e7532e46ec
4
- data.tar.gz: 2d73e184d76e622527418ee6f7d631d94af443d0e64af90784d57e924eee7377
3
+ metadata.gz: 82f147cd96182a6ca152eac3fee6a96f96ece8d3c209430c25b65a3a2a9e77bc
4
+ data.tar.gz: 668c06b6d9d999e412dd5c69d3c9ce756940baea19be40d54d1434104abf01ee
5
5
  SHA512:
6
- metadata.gz: d3df91d0240c5974605780a6a20adfbe251421b85232c12fd422bd222f42e5822cb4896aeb08ea6c9e0103cc451c80d6018a1dd0ef1eec4f43f19fc21b4890fd
7
- data.tar.gz: 455b9ed794b025f0c05235f6163053938565c3762f053469a0c9f3855de83918460bced3b28ebfaa56f2ca77fc41f996ed114fe10e7f99b003a484d7f23e0682
6
+ metadata.gz: fde22cc83423b2cd35c3b1bc5755a34bf47808cfe0916c3e86488fdecdd28e1895fe6167af1e5cc941b214144e65141c22b46a0dfc409bef0de83a540c2a9537
7
+ data.tar.gz: eab5b8de5a932f52ee03d598bc37f45b69289390e3002dc33c9026ddbbb5e3d082a723b7acb5db45ea0f2cd56c767804bc141b8eefd6b983fecfb728c820b6be
@@ -0,0 +1,6 @@
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: "github-actions"
4
+ directory: "/"
5
+ schedule:
6
+ interval: "weekly"
@@ -0,0 +1,34 @@
1
+ name: ci
2
+ on: [pull_request, push]
3
+
4
+ jobs:
5
+ test:
6
+ strategy:
7
+ fail-fast: false
8
+ matrix:
9
+ ruby:
10
+ - '3.3'
11
+ - '3.2'
12
+ - '3.1'
13
+ - ruby-head
14
+ rails_version:
15
+ - '7.2'
16
+ - '6.1'
17
+ exclude:
18
+ - ruby: '3.2'
19
+ rails_version: '6.1'
20
+ - ruby: '3.3'
21
+ rails_version: '6.1'
22
+ - ruby: ruby-head
23
+ rails_version: '6.1'
24
+ runs-on: ubuntu-latest
25
+ env:
26
+ BUNDLE_GEMFILE: gemfiles/${{ matrix.rails_version }}.gemfile
27
+ steps:
28
+ - uses: actions/checkout@v4
29
+ - uses: ruby/setup-ruby@v1
30
+ with:
31
+ bundler: true
32
+ ruby-version: ${{ matrix.ruby }}
33
+ bundler-cache: true # runs 'bundle install' and caches installed gems automatically
34
+ - run: bundle exec rake
data/.gitignore CHANGED
@@ -7,3 +7,4 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+ .idea
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # ActiveFlag - Bit array for ActiveRecord
2
2
 
3
- [![Build Status](https://travis-ci.org/kenn/active_flag.svg)](https://travis-ci.org/kenn/active_flag)
3
+ ![Build Status](https://github.com/kenn/active_flag/actions/workflows/ci.yml/badge.svg)
4
4
 
5
5
  Store up to 64 multiple flags ([bit array](https://en.wikipedia.org/wiki/Bit_array)) in a single integer column with ActiveRecord. From a UI standpoint, it can be used as a multi-select checkbox storage.
6
6
 
@@ -43,6 +43,9 @@ Profile.languages.to_array(3) #=> [:english, :spanish]
43
43
 
44
44
  # Scope methods
45
45
  Profile.where_languages(:french, :spanish) #=> SELECT * FROM profiles WHERE languages & 10 > 0
46
+ Profile.where_all_languages(:french, :spanish) #=> SELECT * FROM profiles WHERE languages & 10 = 10
47
+ Profile.where_not_languages(:french, :spanish) #=> SELECT * FROM profiles WHERE languages & 10 = 0
48
+ Profile.where_not_all_languages(:french, :spanish) #=> SELECT * FROM profiles WHERE languages & 10 < 10
46
49
  Profile.languages.set_all!(:chinese) #=> UPDATE "profiles" SET languages = COALESCE(languages, 0) | 4
47
50
  Profile.languages.unset_all!(:chinese) #=> UPDATE "profiles" SET languages = COALESCE(languages, 0) & ~4
48
51
  ```
@@ -67,7 +70,8 @@ add_column :users, :languages, :integer, null: false, default: 0, limit: 8
67
70
 
68
71
  ## Query
69
72
 
70
- For a querying purpose, use `where_[column]` scope.
73
+ For a querying purpose, use `where_[column]`, `where_all_[column]`,
74
+ `where_not_[column]` and `where_not_all_[column]` scopes.
71
75
 
72
76
  ```ruby
73
77
  Profile.where_languages(:french) #=> SELECT * FROM profiles WHERE languages & 8 > 0
@@ -79,12 +83,24 @@ Also takes multiple values.
79
83
  Profile.where_languages(:french, :spanish) #=> SELECT * FROM profiles WHERE languages & 10 > 0
80
84
  ```
81
85
 
82
- By default, it searches with `or` operation, so the query above returns profiles that have either French or Spanish.
86
+ By default, it returns profiles that have either French or Spanish.
83
87
 
84
- If you want to change it to `and` operation, you can specify:
88
+ To get profiles that have both French and Spanish, use:
85
89
 
86
90
  ```ruby
87
- Profile.where_languages(:french, :spanish, op: :and) #=> SELECT * FROM profiles WHERE languages = 10
91
+ Profile.where_all_languages(:french, :spanish) #=> SELECT * FROM profiles WHERE languages & 10 = 10
92
+ ```
93
+
94
+ To get profiles that do not have either French or Spanish, use:
95
+
96
+ ```ruby
97
+ Profile.where_not_languages(:french, :spanish) #=> SELECT * FROM profiles WHERE languages & 10 = 0
98
+ ```
99
+
100
+ To get profiles that do not have both French and Spanish, use:
101
+
102
+ ```ruby
103
+ Profile.where_not_all_languages(:french, :spanish) #=> SELECT * FROM profiles WHERE languages & 10 < 10
88
104
  ```
89
105
 
90
106
  ## Translation
data/gemfiles/5.0.gemfile CHANGED
@@ -1,12 +1,5 @@
1
- source "https://rubygems.org"
1
+ source 'https://rubygems.org'
2
2
 
3
- gem "activerecord", "~> 5.0"
3
+ gem 'activerecord', '~> 5.0.0'
4
4
 
5
- group :development, :test do
6
- gem "bundler"
7
- gem "rake"
8
- gem "minitest"
9
- gem "sqlite3"
10
- end
11
-
12
- gemspec :path => "../"
5
+ gemspec path: '../'
data/gemfiles/5.1.gemfile CHANGED
@@ -1,12 +1,5 @@
1
- source "https://rubygems.org"
1
+ source 'https://rubygems.org'
2
2
 
3
- gem "activerecord", "~> 5.1"
3
+ gem 'activerecord', '~> 5.1.1'
4
4
 
5
- group :development, :test do
6
- gem "bundler"
7
- gem "rake"
8
- gem "minitest"
9
- gem "sqlite3"
10
- end
11
-
12
- gemspec :path => "../"
5
+ gemspec path: '../'
data/gemfiles/5.2.gemfile CHANGED
@@ -1,12 +1,5 @@
1
- source "https://rubygems.org"
1
+ source 'https://rubygems.org'
2
2
 
3
- gem "activerecord", "~> 5.2"
3
+ gem 'activerecord', '~> 5.2.0'
4
4
 
5
- group :development, :test do
6
- gem "bundler"
7
- gem "rake"
8
- gem "minitest"
9
- gem "sqlite3"
10
- end
11
-
12
- gemspec :path => "../"
5
+ gemspec path: '../'
data/gemfiles/6.0.gemfile CHANGED
@@ -1,12 +1,5 @@
1
- source "https://rubygems.org"
1
+ source 'https://rubygems.org'
2
2
 
3
- gem "activerecord", "~> 6"
3
+ gem 'activerecord', '~> 6.0.0'
4
4
 
5
- group :development, :test do
6
- gem "bundler"
7
- gem "rake"
8
- gem "minitest"
9
- gem "sqlite3"
10
- end
11
-
12
- gemspec :path => "../"
5
+ gemspec path: '../'
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'activerecord', '~> 6.1.0'
4
+
5
+ gemspec path: '../'
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'activerecord', '~> 7.0.0'
4
+
5
+ gemspec path: '../'
@@ -1,3 +1,3 @@
1
1
  module ActiveFlag
2
- VERSION = '1.5.2'
2
+ VERSION = '2.0.0'
3
3
  end
data/lib/active_flag.rb CHANGED
@@ -35,14 +35,31 @@ module ActiveFlag
35
35
 
36
36
  # Scopes
37
37
  define_singleton_method "where_#{column}" do |*args|
38
- options = args.extract_options!
39
- integer = active_flags[column].to_i(args)
40
- column_name = connection.quote_table_name_for_assignment(table_name, column)
41
- if options[:op] == :and
42
- where("#{column_name} & #{integer} = #{integer}")
43
- else
44
- where("#{column_name} & #{integer} > 0")
45
- end
38
+ integer, column_name = send("_where_#{column}", *args)
39
+ where("#{column_name} & #{integer} > 0")
40
+ end
41
+
42
+ define_singleton_method "where_all_#{column}" do |*args|
43
+ integer, column_name = send("_where_#{column}", *args)
44
+ where("#{column_name} & #{integer} = #{integer}")
45
+ end
46
+
47
+ define_singleton_method "where_not_#{column}" do |*args|
48
+ integer, column_name = send("_where_#{column}", *args)
49
+ where("#{column_name} & #{integer} = 0")
50
+ end
51
+
52
+ define_singleton_method "where_not_all_#{column}" do |*args|
53
+ integer, column_name = send("_where_#{column}", *args)
54
+ where("#{column_name} & #{integer} < #{integer}")
55
+ end
56
+
57
+ # utility method to extract parameters
58
+ define_singleton_method "_where_#{column}" do |*args|
59
+ return [
60
+ active_flags[column].to_i(args),
61
+ "#{connection.quote_table_name(table_name)}.#{connection.quote_column_name(column)}"
62
+ ]
46
63
  end
47
64
  end
48
65
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_flag
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.2
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kenn Ejima
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-01-30 00:00:00.000000000 Z
11
+ date: 2024-09-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -87,8 +87,9 @@ executables: []
87
87
  extensions: []
88
88
  extra_rdoc_files: []
89
89
  files:
90
+ - ".github/dependabot.yml"
91
+ - ".github/workflows/ci.yml"
90
92
  - ".gitignore"
91
- - ".travis.yml"
92
93
  - Gemfile
93
94
  - LICENSE
94
95
  - README.md
@@ -100,6 +101,8 @@ files:
100
101
  - gemfiles/5.1.gemfile
101
102
  - gemfiles/5.2.gemfile
102
103
  - gemfiles/6.0.gemfile
104
+ - gemfiles/6.1.gemfile
105
+ - gemfiles/7.0.gemfile
103
106
  - lib/active_flag.rb
104
107
  - lib/active_flag/definition.rb
105
108
  - lib/active_flag/railtie.rb
@@ -123,7 +126,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
123
126
  - !ruby/object:Gem::Version
124
127
  version: '0'
125
128
  requirements: []
126
- rubygems_version: 3.0.9
129
+ rubygems_version: 3.5.16
127
130
  signing_key:
128
131
  specification_version: 4
129
132
  summary: Bit array for ActiveRecord
data/.travis.yml DELETED
@@ -1,11 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 2.5
4
- - 2.6
5
- - 2.7
6
- before_install: gem install bundler -v 1.16.2
7
- gemfile:
8
- - gemfiles/5.0.gemfile
9
- - gemfiles/5.1.gemfile
10
- - gemfiles/5.2.gemfile
11
- - gemfiles/6.0.gemfile