active_queryable 0.3.1 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ca76d46d098d260a1f59a1fd6e50d59cbab69eb95ba87f25470ccb08aa3050f2
4
- data.tar.gz: 9562f2b4d7a4cce6ba1ba6bb070c6e6d9cf031d6205bf1006e5b5c1f21566ed4
3
+ metadata.gz: c25dd06549532fe641c473358fea0eb2b504e2b17c4dc72ac0e872e79ed17457
4
+ data.tar.gz: 2458c9d3dac13e9a56cc7df37131a8b1e2d0c0b30687f928cd9970ff93c9498b
5
5
  SHA512:
6
- metadata.gz: 5ec24780124afa2fd02e2d6bdf9a4f54f6dd980c8852adc43c4ae37144f887d54eccbdebf5e8d50765b3cc3e051762f4c1e62f7006a3a5385d5ed6962e3ce22f
7
- data.tar.gz: aaf987e005a9f87b39ae00f63adaf7791a11b0facc962ae2f9b70e541e74f7b0281e1d71e6428ba71b97c7ba924dd20cf08b126e960430f9ecf8ef88d0ec9d0d
6
+ metadata.gz: 96b0c2d39034f8a646936efca9ed2a5744587ce826ba7f3a1ca7dce1a33de3966fc697502825aac74fbbffe1ee692d914c568090cab6ea592df756a4d05fafba
7
+ data.tar.gz: 00d9697d742d1cf31317ce7769b36619c1e06e8c2044de59b1ab15b13bc0c695e2409f0817590e0720b725951010cf004e02db29eeb29aba77a767e3e524f01a
@@ -2,5 +2,5 @@
2
2
 
3
3
  module ActiveQueryable
4
4
  # @return [String] the version of the gem
5
- VERSION = '0.3.1'
5
+ VERSION = '0.4.1'
6
6
  end
@@ -70,6 +70,7 @@ module ActiveQueryable
70
70
  queryable_configure_options(options)
71
71
 
72
72
  scope :query_by, ->(params) { queryable_scope(params) }
73
+ scope :of_ids, ->(ids) { where(id: ids) }
73
74
  scope :of_not, ->(ids) { where.not(id: ids) }
74
75
  end
75
76
 
@@ -89,7 +90,7 @@ module ActiveQueryable
89
90
  # @return [void]
90
91
  def expand_queryable(options)
91
92
  self._queryable_expandable_filter_keys ||= []
92
- self._queryable_expandable_filter_keys += ((options[:filter] || [])).map(&:to_sym)
93
+ self._queryable_expandable_filter_keys += (options[:filter] || []).map(&:to_sym)
93
94
  end
94
95
 
95
96
  # @param params [Hash,ActionController::Parameters]
@@ -102,9 +103,7 @@ module ActiveQueryable
102
103
  def queryable_scope(params)
103
104
  params = params.to_unsafe_h if params.respond_to? :to_unsafe_h
104
105
  params = params.with_indifferent_access if params.respond_to?(:with_indifferent_access)
105
- params.each_key do |k|
106
- QUERYABLE_VALID_PARAMS.include?(k.to_sym) || Rails.logger.error("Invalid key #{k} in queryable")
107
- end
106
+ queryable_log_unpermitted_params(params)
108
107
 
109
108
  order_params = queryable_validate_order_params(params[:sort])
110
109
  query = queryable_parse_order_scope(order_params, self)
@@ -114,6 +113,18 @@ module ActiveQueryable
114
113
 
115
114
  private
116
115
 
116
+ # @param params [Hash,ActionController::Parameters]
117
+ # @return [void]
118
+ def queryable_log_unpermitted_params(params)
119
+ params.each_key do |k|
120
+ next if QUERYABLE_VALID_PARAMS.include?(k.to_sym)
121
+
122
+ Rails.logger.debug(
123
+ "Unsupported key `#{k}` passed to `query_by` will be ignored. Allowed keys: #{QUERYABLE_VALID_PARAMS.join(', ')}"
124
+ )
125
+ end
126
+ end
127
+
117
128
  # @option options [Hash<Symbol,Symbol>] :order { id: :asc }
118
129
  # @option options [Integer] :page 1
119
130
  # @option options [Integer] :per 25
@@ -123,7 +134,7 @@ module ActiveQueryable
123
134
  self._queryable_default_order = options[:order] || { id: :asc }
124
135
  self._queryable_default_page = options[:page] || 1
125
136
  self._queryable_default_per = options[:per] || 25
126
- self._queryable_filter_keys = (((options[:filter] || [])).map(&:to_sym))
137
+ self._queryable_filter_keys = ((options[:filter] || []).map(&:to_sym))
127
138
  end
128
139
 
129
140
  # @param params [Hash,ActionController::Parameters]
@@ -165,7 +176,7 @@ module ActiveQueryable
165
176
  page_params = {}
166
177
  if params[:page].respond_to?(:dig)
167
178
  page_params[:page] = params.dig(:page, :number) || _queryable_default_page
168
- page_params[:per] = params.dig(:page, :size) || params[:per] || _queryable_default_per
179
+ page_params[:per] = params.dig(:page, :size) || _queryable_default_per
169
180
  else
170
181
  page_params[:page] = params[:page] || _queryable_default_page
171
182
  page_params[:per] = params[:per] || _queryable_default_per
@@ -16,8 +16,8 @@ describe 'Pagination' do
16
16
  expect(query.to_sql).to include('LIMIT 2 OFFSET 2')
17
17
  end
18
18
 
19
- it 'ignores invalid values of page' do
19
+ it 'ignores per when page is an object' do
20
20
  query = Person.query_by(page: {}, per: 20)
21
- expect(query.to_sql).to include('LIMIT 20 OFFSET 0')
21
+ expect(query.to_sql).to include('LIMIT 25 OFFSET 0')
22
22
  end
23
23
  end
data/spec/spec_helper.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require 'logger'
1
2
  require 'active_support'
2
3
  require 'rspec'
3
4
  require 'active_record'
@@ -1,9 +1,30 @@
1
1
  require 'active_record'
2
2
 
3
- ActiveRecord::Base.establish_connection(
4
- adapter: 'sqlite3',
5
- database: ':memory:'
6
- )
3
+ if ENV['ACTIVE_RECORD_ADAPTER'] == 'mysql'
4
+ puts 'Running on MySQL...'
5
+ ActiveRecord::Base.establish_connection(
6
+ adapter: 'mysql2',
7
+ host: ENV['DB_HOST'] || '127.0.0.1',
8
+ username: ENV['DB_USERNAME'] || 'root',
9
+ password: ENV['DB_PASSWORD'],
10
+ database: 'acts_as_nosql'
11
+ )
12
+ elsif ENV['ACTIVE_RECORD_ADAPTER'] == 'postgresql'
13
+ puts 'Running on PostgreSQL...'
14
+ ActiveRecord::Base.establish_connection(
15
+ adapter: 'postgresql',
16
+ database: 'acts_as_nosql',
17
+ host: ENV['DB_HOST'] || '127.0.0.1',
18
+ username: ENV['DB_USERNAME'] || ENV['POSTGRES_USER'] || 'postgres',
19
+ password: ENV['DB_PASSWORD'] || ENV['POSTGRES_PASSWORD']
20
+ )
21
+ else
22
+ puts 'Running on SQLite...'
23
+ ActiveRecord::Base.establish_connection(
24
+ adapter: 'sqlite3',
25
+ database: ':memory:'
26
+ )
27
+ end
7
28
 
8
29
  class Common < ActiveRecord::Base
9
30
  self.abstract_class = true
metadata CHANGED
@@ -1,11 +1,11 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_queryable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mònade
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
  date: 2019-12-16 00:00:00.000000000 Z
@@ -16,20 +16,40 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '5'
19
+ version: '6'
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '8'
22
+ version: '9'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- version: '5'
29
+ version: '6'
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '8'
32
+ version: '9'
33
+ - !ruby/object:Gem::Dependency
34
+ name: activerecord
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '6'
40
+ - - "<"
41
+ - !ruby/object:Gem::Version
42
+ version: '9'
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '6'
50
+ - - "<"
51
+ - !ruby/object:Gem::Version
52
+ version: '9'
33
53
  - !ruby/object:Gem::Dependency
34
54
  name: kaminari-activerecord
35
55
  requirement: !ruby/object:Gem::Requirement
@@ -91,7 +111,7 @@ homepage: https://rubygems.org/gems/active_queryable
91
111
  licenses:
92
112
  - MIT
93
113
  metadata: {}
94
- post_install_message:
114
+ post_install_message:
95
115
  rdoc_options: []
96
116
  require_paths:
97
117
  - lib
@@ -99,15 +119,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
99
119
  requirements:
100
120
  - - ">="
101
121
  - !ruby/object:Gem::Version
102
- version: 2.7.0
122
+ version: 3.0.0
103
123
  required_rubygems_version: !ruby/object:Gem::Requirement
104
124
  requirements:
105
125
  - - ">="
106
126
  - !ruby/object:Gem::Version
107
127
  version: '0'
108
128
  requirements: []
109
- rubygems_version: 3.2.33
110
- signing_key:
129
+ rubygems_version: 3.4.6
130
+ signing_key:
111
131
  specification_version: 4
112
132
  summary: Gem to make easier model's filtering, sorting and pagination
113
133
  test_files: