miscellany 0.1.16 → 0.1.18
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1dea6efd8728954e80a8a249f749dd8133ecfcf71fb6b4a3b3acf248b662fca8
|
4
|
+
data.tar.gz: bd567ce813d303ca03d8d87f8faa4a312d2417b934bb1ee8c3d2781b99126f88
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 66f32e979d580c4297c1155f6bc87203ec808420856636724a257d07ca062ffe5d5ecd073aaa0fa0b09efb781f033affce87faa579b0007bd7f4ffe46c82fda3
|
7
|
+
data.tar.gz: 54210f971ad74cd8d14b4934cb36d155943626b5e66190c682c294fdcd30f3b315cf2b5dbae268ce70a1213726e294978c80b080fdf8422bd1256a4f47dd3f37
|
@@ -7,8 +7,8 @@ module Miscellany
|
|
7
7
|
include HttpErrorHandling
|
8
8
|
|
9
9
|
# Deprecated
|
10
|
-
def slice_results(
|
11
|
-
@sliced_data = sliced_json(
|
10
|
+
def slice_results(*args, **kwargs, &blk)
|
11
|
+
@sliced_data = sliced_json(*args, **kwargs, &blk)
|
12
12
|
end
|
13
13
|
|
14
14
|
def sliced_json(
|
@@ -198,7 +198,12 @@ module Miscellany
|
|
198
198
|
elsif items.is_a?(ActiveRecord::Relation)
|
199
199
|
offset, limit = slice_bounds
|
200
200
|
limit -= offset unless limit.nil?
|
201
|
-
|
201
|
+
|
202
|
+
query = items
|
203
|
+
sort_clause = sort_sql
|
204
|
+
query = query.order(Arel.sql(sort_clause)) if sort_clause.present?
|
205
|
+
|
206
|
+
query.limit(limit).offset(offset).to_a
|
202
207
|
elsif defined?(Miscellany::ComplexQuery) && items.is_a?(Miscellany::ComplexQuery)
|
203
208
|
offset, limit = slice_bounds
|
204
209
|
limit -= offset unless limit.nil?
|
data/lib/miscellany/sort_lang.rb
CHANGED
@@ -26,7 +26,7 @@ module Miscellany
|
|
26
26
|
sorts.map do |sort|
|
27
27
|
order = sort[:order] || 'ASC'
|
28
28
|
if sort[:column].is_a?(Proc)
|
29
|
-
sort[:column].call(
|
29
|
+
sort[:column].call(order)
|
30
30
|
else
|
31
31
|
desired_nulls = (sort[:nulls] || :low).to_s.downcase.to_sym
|
32
32
|
nulls = case desired_nulls
|
@@ -93,6 +93,7 @@ module Miscellany
|
|
93
93
|
sorts.each do |s|
|
94
94
|
if s.is_a?(Hash)
|
95
95
|
s.each do |k,v|
|
96
|
+
k = k.to_s
|
96
97
|
sort_hash = normalize_sort(v, key: k)
|
97
98
|
norm_sorts[k] = sort_hash
|
98
99
|
end
|
data/lib/miscellany/version.rb
CHANGED
@@ -129,6 +129,19 @@ describe Miscellany::SlicedResponse do
|
|
129
129
|
|
130
130
|
expect(subject.sliced_json(ARModel.all, { page: "all" }, allow_all: true, **slice_config)).to be_a Hash
|
131
131
|
end
|
132
|
+
|
133
|
+
context "with Hash-based valid_sorts" do
|
134
|
+
let(:source) { ARModel.all }
|
135
|
+
|
136
|
+
before(:each) do
|
137
|
+
slice_config[:valid_sorts] = [
|
138
|
+
title: ->(dir) { "title #{dir}" }
|
139
|
+
]
|
140
|
+
end
|
141
|
+
|
142
|
+
include_examples "basic functionality"
|
143
|
+
include_examples "sortable"
|
144
|
+
end
|
132
145
|
end
|
133
146
|
|
134
147
|
describe "#bearcat_as_sliced_json" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.18
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ethan Knapp
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-10-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|