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 +4 -4
- data/.github/dependabot.yml +6 -0
- data/.github/workflows/ci.yml +34 -0
- data/.gitignore +1 -0
- data/README.md +21 -5
- data/gemfiles/5.0.gemfile +3 -10
- data/gemfiles/5.1.gemfile +3 -10
- data/gemfiles/5.2.gemfile +3 -10
- data/gemfiles/6.0.gemfile +3 -10
- data/gemfiles/6.1.gemfile +5 -0
- data/gemfiles/7.0.gemfile +5 -0
- data/lib/active_flag/version.rb +1 -1
- data/lib/active_flag.rb +25 -8
- metadata +7 -4
- data/.travis.yml +0 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 82f147cd96182a6ca152eac3fee6a96f96ece8d3c209430c25b65a3a2a9e77bc
|
4
|
+
data.tar.gz: 668c06b6d9d999e412dd5c69d3c9ce756940baea19be40d54d1434104abf01ee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fde22cc83423b2cd35c3b1bc5755a34bf47808cfe0916c3e86488fdecdd28e1895fe6167af1e5cc941b214144e65141c22b46a0dfc409bef0de83a540c2a9537
|
7
|
+
data.tar.gz: eab5b8de5a932f52ee03d598bc37f45b69289390e3002dc33c9026ddbbb5e3d082a723b7acb5db45ea0f2cd56c767804bc141b8eefd6b983fecfb728c820b6be
|
@@ -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
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# ActiveFlag - Bit array for ActiveRecord
|
2
2
|
|
3
|
-
|
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]`
|
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
|
86
|
+
By default, it returns profiles that have either French or Spanish.
|
83
87
|
|
84
|
-
|
88
|
+
To get profiles that have both French and Spanish, use:
|
85
89
|
|
86
90
|
```ruby
|
87
|
-
Profile.
|
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
|
1
|
+
source 'https://rubygems.org'
|
2
2
|
|
3
|
-
gem
|
3
|
+
gem 'activerecord', '~> 5.0.0'
|
4
4
|
|
5
|
-
|
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
|
1
|
+
source 'https://rubygems.org'
|
2
2
|
|
3
|
-
gem
|
3
|
+
gem 'activerecord', '~> 5.1.1'
|
4
4
|
|
5
|
-
|
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
|
1
|
+
source 'https://rubygems.org'
|
2
2
|
|
3
|
-
gem
|
3
|
+
gem 'activerecord', '~> 5.2.0'
|
4
4
|
|
5
|
-
|
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
|
1
|
+
source 'https://rubygems.org'
|
2
2
|
|
3
|
-
gem
|
3
|
+
gem 'activerecord', '~> 6.0.0'
|
4
4
|
|
5
|
-
|
6
|
-
gem "bundler"
|
7
|
-
gem "rake"
|
8
|
-
gem "minitest"
|
9
|
-
gem "sqlite3"
|
10
|
-
end
|
11
|
-
|
12
|
-
gemspec :path => "../"
|
5
|
+
gemspec path: '../'
|
data/lib/active_flag/version.rb
CHANGED
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
|
-
|
39
|
-
integer
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
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:
|
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:
|
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.
|
129
|
+
rubygems_version: 3.5.16
|
127
130
|
signing_key:
|
128
131
|
specification_version: 4
|
129
132
|
summary: Bit array for ActiveRecord
|