Skip to content

Commit

Permalink
Support JOIN | Remove op: :and option | v2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
kenn committed Sep 4, 2024
1 parent 3e9744a commit dd2ba0f
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 44 deletions.
40 changes: 11 additions & 29 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,46 +7,28 @@ jobs:
fail-fast: false
matrix:
ruby:
- "3.2"
- "3.1"
- "3.0"
- "2.7"
- "2.6"
- '3.3'
- '3.2'
- '3.1'
- ruby-head
rails_version:
- "7.0"
- "6.1"
- "6.0"
- "5.2"
- '7.2'
- '6.1'
exclude:
- ruby: "2.6"
rails_version: "7.0"
- ruby: "3.0"
rails_version: "5.2"
- ruby: "3.1"
rails_version: "5.2"
- ruby: "3.1"
rails_version: "6.0"
- ruby: "3.2"
rails_version: "5.2"
- ruby: "3.2"
rails_version: "6.0"
- ruby: "3.2"
rails_version: "6.1"
- ruby: '3.2'
rails_version: '6.1'
- ruby: '3.3'
rails_version: '6.1'
- ruby: ruby-head
rails_version: "5.2"
- ruby: ruby-head
rails_version: "6.0"
- ruby: ruby-head
rails_version: "6.1"
rails_version: '6.1'
runs-on: ubuntu-latest
env:
BUNDLE_GEMFILE: gemfiles/${{ matrix.rails_version }}.gemfile
steps:
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
bundler: ${{ matrix.bundler }}
bundler: true
ruby-version: ${{ matrix.ruby }}
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
- run: bundle exec rake
16 changes: 5 additions & 11 deletions lib/active_flag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,34 +35,28 @@ def flag(column, keys)

# Scopes
define_singleton_method "where_#{column}" do |*args|
options, integer, column_name = send "_where_#{column}", *args
if options[:op] == :and
ActiveSupport::Deprecation.warn('op: :and is deprecated, use where_all instead')
where("#{column_name} & #{integer} = #{integer}")
else
where("#{column_name} & #{integer} > 0")
end
integer, column_name = send("_where_#{column}", *args)
where("#{column_name} & #{integer} > 0")
end

define_singleton_method "where_all_#{column}" do |*args|
_options, integer, column_name = send "_where_#{column}", *args
integer, column_name = send("_where_#{column}", *args)
where("#{column_name} & #{integer} = #{integer}")
end

define_singleton_method "where_not_#{column}" do |*args|
_options, integer, column_name = send "_where_#{column}", *args
integer, column_name = send("_where_#{column}", *args)
where("#{column_name} & #{integer} = 0")
end

define_singleton_method "where_not_all_#{column}" do |*args|
_options, integer, column_name = send "_where_#{column}", *args
integer, column_name = send("_where_#{column}", *args)
where("#{column_name} & #{integer} < #{integer}")
end

# utility method to extract parameters
define_singleton_method "_where_#{column}" do |*args|
return [
args.extract_options!,
active_flags[column].to_i(args),
"#{connection.quote_table_name(table_name)}.#{connection.quote_column_name(column)}"
]
Expand Down
2 changes: 1 addition & 1 deletion lib/active_flag/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module ActiveFlag
VERSION = '1.7.0'
VERSION = '2.0.0'
end
3 changes: 0 additions & 3 deletions test/active_flag_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,6 @@ def test_scope
assert_equal Profile.where_languages(:english).count, 2
assert_equal Profile.where_languages(:japanese).count, 2
assert_equal Profile.where_languages(:english, :japanese).count, 3
ActiveSupport::Deprecation.silence do
assert_equal Profile.where_languages(:english, :japanese, op: :and).count, 1
end
assert_equal Profile.where_all_languages(:english, :japanese).count, 1
assert_equal Profile.where_not_languages(:english).count, 1
assert_equal Profile.where_not_languages(:english, :japanese).count, 0
Expand Down

0 comments on commit dd2ba0f

Please sign in to comment.