Skip to content

Commit

Permalink
feat: new version
Browse files Browse the repository at this point in the history
  • Loading branch information
ProGM committed Jan 20, 2025
1 parent 3424fda commit ac33534
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 30 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/gem-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ jobs:

steps:
- uses: actions/checkout@v3
- name: Set up Ruby 3.0
- name: Set up Ruby 3.2
uses: ruby/setup-ruby@v1
with:
ruby-version: '3.0'
ruby-version: '3.2.1'

- name: Publish to GPR
run: |
Expand Down
16 changes: 2 additions & 14 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,7 @@ on:
push:
pull_request:
schedule:
- cron: "0 0 1 * *"
- cron: '0 0 1 * *'
jobs:
test:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest]
ruby: [3.1, 3.2, 3.3, head, truffleruby]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
- run: bundle exec rspec
uses: monade/reusable-workflows/.github/workflows/monade-ruby-rails-gems-spec.yml@main
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
# Changelog
All notable changes to this project made by Monade Team are documented in this file. For info refer to team@monade.io

## [0.4.0] - 2025-01-20
### Added
- Support for rails 8
- Default filter `of_ids`

### Changed
- Default when `page` is an object, `per` will be now ignored

### Removed
- Support for rails 5
- Support for ruby 2.7

## [0.3.1] - 2022-12-11
### Added
- Yard documentation
Expand Down
11 changes: 9 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
source "https://rubygems.org"
gemspec

rails_version = ENV['CI_RAILS_VERSION'] || '>= 0.0'

gem 'activesupport', rails_version
gem 'activerecord', rails_version
gem 'kaminari-activerecord'
gem 'solargraph'
gem 'sqlite3', '~> 1.7.3'
if ['~> 8.0.0', '>= 0', '>= 0.0'].include?(rails_version)
gem 'sqlite3', '~> 2'
else
gem 'sqlite3', '~> 1.7.3'
end
gem 'yard'
5 changes: 3 additions & 2 deletions active_queryable.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ Gem::Specification.new do |s|
s.email = 'team@monade.io'
s.files = Dir['lib/**/*']
s.test_files = Dir['spec/**/*']
s.required_ruby_version = '>= 2.7.0'
s.required_ruby_version = '>= 3.0.0'
s.homepage = 'https://rubygems.org/gems/active_queryable'
s.license = 'MIT'
s.add_dependency 'activesupport', ['>= 5', '< 8']
s.add_dependency 'activesupport', ['>= 6', '< 9']
s.add_dependency 'activerecord', ['>= 6', '< 9']
s.add_dependency 'kaminari-activerecord'
s.add_development_dependency 'rspec', '~> 3'
s.add_development_dependency 'rubocop'
Expand Down
7 changes: 4 additions & 3 deletions lib/active_queryable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ def queryable(options)
queryable_configure_options(options)

scope :query_by, ->(params) { queryable_scope(params) }
scope :of_ids, ->(ids) { where(id: ids) }
scope :of_not, ->(ids) { where.not(id: ids) }
end

Expand All @@ -89,7 +90,7 @@ def queryable(options)
# @return [void]
def expand_queryable(options)
self._queryable_expandable_filter_keys ||= []
self._queryable_expandable_filter_keys += ((options[:filter] || [])).map(&:to_sym)
self._queryable_expandable_filter_keys += (options[:filter] || []).map(&:to_sym)
end

# @param params [Hash,ActionController::Parameters]
Expand Down Expand Up @@ -123,7 +124,7 @@ def queryable_configure_options(options)
self._queryable_default_order = options[:order] || { id: :asc }
self._queryable_default_page = options[:page] || 1
self._queryable_default_per = options[:per] || 25
self._queryable_filter_keys = (((options[:filter] || [])).map(&:to_sym))
self._queryable_filter_keys = ((options[:filter] || []).map(&:to_sym))
end

# @param params [Hash,ActionController::Parameters]
Expand Down Expand Up @@ -165,7 +166,7 @@ def queryable_validate_page_params(params)
page_params = {}
if params[:page].respond_to?(:dig)
page_params[:page] = params.dig(:page, :number) || _queryable_default_page
page_params[:per] = params.dig(:page, :size) || params[:per] || _queryable_default_per
page_params[:per] = params.dig(:page, :size) || _queryable_default_per
else
page_params[:page] = params[:page] || _queryable_default_page
page_params[:per] = params[:per] || _queryable_default_per
Expand Down
2 changes: 1 addition & 1 deletion lib/active_queryable/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

module ActiveQueryable
# @return [String] the version of the gem
VERSION = '0.3.1'
VERSION = '0.4.0'
end
4 changes: 2 additions & 2 deletions spec/active_queryable/pagination_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
expect(query.to_sql).to include('LIMIT 2 OFFSET 2')
end

it 'ignores invalid values of page' do
it 'ignores per when page is an object' do
query = Person.query_by(page: {}, per: 20)
expect(query.to_sql).to include('LIMIT 20 OFFSET 0')
expect(query.to_sql).to include('LIMIT 25 OFFSET 0')
end
end
29 changes: 25 additions & 4 deletions spec/support/schema.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,30 @@
require 'active_record'

ActiveRecord::Base.establish_connection(
adapter: 'sqlite3',
database: ':memory:'
)
if ENV['ACTIVE_RECORD_ADAPTER'] == 'mysql'
puts 'Running on MySQL...'
ActiveRecord::Base.establish_connection(
adapter: 'mysql2',
host: ENV['DB_HOST'] || '127.0.0.1',
username: ENV['DB_USERNAME'] || 'root',
password: ENV['DB_PASSWORD'],
database: 'acts_as_nosql'
)
elsif ENV['ACTIVE_RECORD_ADAPTER'] == 'postgresql'
puts 'Running on PostgreSQL...'
ActiveRecord::Base.establish_connection(
adapter: 'postgresql',
database: 'acts_as_nosql',
host: ENV['DB_HOST'] || '127.0.0.1',
username: ENV['DB_USERNAME'] || ENV['POSTGRES_USER'] || 'postgres',
password: ENV['DB_PASSWORD'] || ENV['POSTGRES_PASSWORD']
)
else
puts 'Running on SQLite...'
ActiveRecord::Base.establish_connection(
adapter: 'sqlite3',
database: ':memory:'
)
end

class Common < ActiveRecord::Base
self.abstract_class = true
Expand Down

0 comments on commit ac33534

Please sign in to comment.