miscellany 0.1.22 → 0.1.25
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 +4 -4
- data/README.md +0 -0
- data/app/views/miscellany/_slice.json.jbuilder +0 -0
- data/config/initializers/cancancan.rb +0 -0
- data/lib/miscellany/active_record/arbitrary_prefetch.rb +2 -2
- data/lib/miscellany/active_record/batch_matcher.rb +0 -0
- data/lib/miscellany/active_record/batched_destruction.rb +0 -0
- data/lib/miscellany/active_record/complex_query.rb +0 -0
- data/lib/miscellany/active_record/computed_columns.rb +0 -0
- data/lib/miscellany/active_record/custom_preloaders.rb +0 -0
- data/lib/miscellany/active_record/goldiload_value.rb +0 -0
- data/lib/miscellany/batch_processor.rb +0 -0
- data/lib/miscellany/batching_csv_processor.rb +0 -0
- data/lib/miscellany/controller/http_error_handling.rb +0 -0
- data/lib/miscellany/controller/json_uploads.rb +0 -0
- data/lib/miscellany/controller/sliced_response.rb +24 -6
- data/lib/miscellany/jbuilder_partial_block.rb +0 -0
- data/lib/miscellany/local_lru_cache.rb +0 -0
- data/lib/miscellany/param_validator.rb +0 -0
- data/lib/miscellany/sort_lang.rb +4 -2
- data/lib/miscellany/version.rb +1 -1
- data/lib/miscellany.rb +0 -0
- data/miscellany.gemspec +0 -0
- data/spec/db/database.yml +0 -0
- data/spec/miscellany/arbitrary_prefetch_spec.rb +0 -0
- data/spec/miscellany/computed_columns_spec.rb +0 -0
- data/spec/miscellany/goldiload_value_spec.rb +0 -0
- data/spec/miscellany/param_validator_spec.rb +0 -0
- data/spec/miscellany/sliced_response_spec.rb +0 -0
- data/spec/miscellany/sort_lang_spec.rb +6 -3
- data/spec/spec_helper.rb +0 -0
- metadata +6 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4fc8f4d4e764e532f99f3db6e45cdf8c27a9b587a9617fe75b08f54701e5f3a2
|
4
|
+
data.tar.gz: 790a900c2124bbefa4b6d792e76fed386ea2a6ae20037045d69398b7425fe5dd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1c87cc64f1f2c7c41f4b56ff6097d22ad3efe57fef2979fa38951c8c444d648dc24beca35a7a8dd7c61b48956bbd993bab44f3932b5d648c8f64a5b70f4c72db
|
7
|
+
data.tar.gz: d5273475dbab7ef34b58bdc6ff43617a5ee6b722575d02f178a01047c716c6d581b25308b2016de0d4ca3d70dd0ab25a10146e22368b285af36235004694b41e
|
data/README.md
CHANGED
File without changes
|
File without changes
|
File without changes
|
@@ -203,12 +203,12 @@ module Miscellany
|
|
203
203
|
|
204
204
|
base_module ||= mod
|
205
205
|
|
206
|
-
if mod.name.
|
206
|
+
if mod.name.end_with? "Patch"
|
207
207
|
base_full_name = base_module.to_s
|
208
208
|
mod_full_name = mod.to_s
|
209
209
|
mod_rel_name = mod_full_name.sub(base_full_name, '')
|
210
210
|
mod_rel_bits = mod_rel_name.split('::').select(&:present?).map do |bit|
|
211
|
-
bit.
|
211
|
+
bit.end_with?('Patch') ? bit[0..-6] : bit
|
212
212
|
end
|
213
213
|
final_mod_name = [install_base, *mod_rel_bits].select(&:present?).join("::")
|
214
214
|
install_mod = final_mod_name.constantize
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -173,7 +173,7 @@ module Miscellany
|
|
173
173
|
def total_item_count
|
174
174
|
@total_item_count ||= options[:total_count] || begin
|
175
175
|
if items.is_a?(ActiveRecord::Relation)
|
176
|
-
items.
|
176
|
+
items.model.from(items).count
|
177
177
|
elsif items.respond_to?(:count)
|
178
178
|
items.count
|
179
179
|
elsif defined?(Miscellany::ComplexQuery) && items.is_a?(Miscellany::ComplexQuery)
|
@@ -202,6 +202,18 @@ module Miscellany
|
|
202
202
|
limit -= offset unless limit.nil?
|
203
203
|
|
204
204
|
query = items
|
205
|
+
|
206
|
+
applied_sorts.each do |sort|
|
207
|
+
# TODO Throw an error if joins: is present on a non-AR::Relation?
|
208
|
+
if sort[:joins].is_a?(ActiveRecord::Relation)
|
209
|
+
query = query.merge(sort[:joins])
|
210
|
+
elsif sort[:joins].is_a?(Proc)
|
211
|
+
query = sort[:joins].call(query)
|
212
|
+
elsif sort[:joins].present?
|
213
|
+
query = query.joins(sort[:joins])
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
205
217
|
sort_clause = sort_sql
|
206
218
|
query = query.order(Arel.sql(sort_clause)) if sort_clause.present?
|
207
219
|
|
@@ -219,13 +231,19 @@ module Miscellany
|
|
219
231
|
[slice_start, slice_end == -1 ? nil : slice_end]
|
220
232
|
end
|
221
233
|
|
222
|
-
def
|
223
|
-
|
224
|
-
|
234
|
+
def applied_sorts
|
235
|
+
@applied_sorts ||= begin
|
236
|
+
sorts = [ *Array(self.sort), *options[:sort_parser]&.default_sorts]
|
237
|
+
sorts.compact!
|
238
|
+
sorts = Miscellany::SortLang.distinct_sorts(sorts)
|
239
|
+
sorts
|
240
|
+
end
|
241
|
+
end
|
225
242
|
|
226
|
-
|
243
|
+
def sort_sql
|
244
|
+
return nil unless applied_sorts.present?
|
227
245
|
|
228
|
-
Miscellany::SortLang.sqlize(
|
246
|
+
Miscellany::SortLang.sqlize(applied_sorts)
|
229
247
|
end
|
230
248
|
end
|
231
249
|
end
|
File without changes
|
File without changes
|
File without changes
|
data/lib/miscellany/sort_lang.rb
CHANGED
@@ -22,11 +22,11 @@ module Miscellany
|
|
22
22
|
sort.compact
|
23
23
|
end
|
24
24
|
|
25
|
-
def self.
|
25
|
+
def self.distinct_sorts(sorts)
|
26
26
|
seen_sorts = Set.new
|
27
27
|
|
28
28
|
# Only include each sort key/"column" once
|
29
|
-
sorts
|
29
|
+
sorts.select do |sort|
|
30
30
|
sid = sort[:key] || sort[:column]
|
31
31
|
next true unless sid.present?
|
32
32
|
|
@@ -37,7 +37,9 @@ module Miscellany
|
|
37
37
|
true
|
38
38
|
end
|
39
39
|
end
|
40
|
+
end
|
40
41
|
|
42
|
+
def self.sqlize(sorts)
|
41
43
|
sorts.map do |sort|
|
42
44
|
order = sort[:order] || 'ASC'
|
43
45
|
if sort[:column].is_a?(Proc)
|
data/lib/miscellany/version.rb
CHANGED
data/lib/miscellany.rb
CHANGED
File without changes
|
data/miscellany.gemspec
CHANGED
File without changes
|
data/spec/db/database.yml
CHANGED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -30,14 +30,17 @@ describe Miscellany::SortLang do
|
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
|
-
describe ".
|
33
|
+
describe ".distinct_sorts" do
|
34
34
|
it "only includes each sort key once" do
|
35
|
-
|
35
|
+
distinct = Miscellany::SortLang.distinct_sorts([
|
36
36
|
{ column: "created_at", order: "ASC" },
|
37
37
|
{ column: "created_at", order: "DESC" },
|
38
|
-
])
|
38
|
+
])
|
39
|
+
expect(Miscellany::SortLang.sqlize(distinct)).to eql "created_at ASC NULLS FIRST"
|
39
40
|
end
|
41
|
+
end
|
40
42
|
|
43
|
+
describe ".sqlize" do
|
41
44
|
describe "nulls: option" do
|
42
45
|
it "accepts a nulls: option" do
|
43
46
|
expect(Miscellany::SortLang.sqlize([
|
data/spec/spec_helper.rb
CHANGED
File without changes
|
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: miscellany
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.25
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ethan Knapp
|
8
|
-
autorequire:
|
9
8
|
bindir: bin
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: rails
|
@@ -114,7 +113,6 @@ dependencies:
|
|
114
113
|
- - ">="
|
115
114
|
- !ruby/object:Gem::Version
|
116
115
|
version: '0'
|
117
|
-
description:
|
118
116
|
email:
|
119
117
|
- eknapp@instructure.com
|
120
118
|
executables: []
|
@@ -154,7 +152,6 @@ files:
|
|
154
152
|
homepage: https://instructure.com
|
155
153
|
licenses: []
|
156
154
|
metadata: {}
|
157
|
-
post_install_message:
|
158
155
|
rdoc_options: []
|
159
156
|
require_paths:
|
160
157
|
- lib
|
@@ -169,16 +166,15 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
169
166
|
- !ruby/object:Gem::Version
|
170
167
|
version: '0'
|
171
168
|
requirements: []
|
172
|
-
rubygems_version: 3.
|
173
|
-
signing_key:
|
169
|
+
rubygems_version: 3.6.7
|
174
170
|
specification_version: 4
|
175
171
|
summary: Gem for a bunch of random, re-usable Rails Concerns & Helpers
|
176
172
|
test_files:
|
177
173
|
- spec/db/database.yml
|
178
|
-
- spec/miscellany/sort_lang_spec.rb
|
179
174
|
- spec/miscellany/arbitrary_prefetch_spec.rb
|
180
|
-
- spec/miscellany/sliced_response_spec.rb
|
181
|
-
- spec/miscellany/param_validator_spec.rb
|
182
175
|
- spec/miscellany/computed_columns_spec.rb
|
183
176
|
- spec/miscellany/goldiload_value_spec.rb
|
177
|
+
- spec/miscellany/param_validator_spec.rb
|
178
|
+
- spec/miscellany/sliced_response_spec.rb
|
179
|
+
- spec/miscellany/sort_lang_spec.rb
|
184
180
|
- spec/spec_helper.rb
|