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: d919e8dffeb9e12448e4e1a65f0e3c3015b9dd759164e746a59560af0797ea32
4
- data.tar.gz: dd0a2c007d8980d1dd7d5995571aa7a9e1a4346099c23c279fd4f7c853851535
3
+ metadata.gz: 1dea6efd8728954e80a8a249f749dd8133ecfcf71fb6b4a3b3acf248b662fca8
4
+ data.tar.gz: bd567ce813d303ca03d8d87f8faa4a312d2417b934bb1ee8c3d2781b99126f88
5
5
  SHA512:
6
- metadata.gz: 97f892b692386c7c924a2b082ddb34787a6870c9bad7cc378d426a6fe8e288a7d47f33b570596c4e948a24decc51882b9da859d8e9fef3d5cbe8ad13c49cecdf
7
- data.tar.gz: 0115b26046212f6d56bbac869097a3e7b69e2c2b1756d3b33b38a02b9b361df61c478f2d930f343577e53bc1f3181b83e9cbcee1be2e188e6640a38901b8c357
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(queryset, **kwargs)
11
- @sliced_data = sliced_json(queryset, **kwargs) { |x| x }
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
- items.order(Arel.sql(sort_sql)).limit(limit).offset(offset).to_a
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?
@@ -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(qset, order)
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
@@ -1,3 +1,3 @@
1
1
  module Miscellany
2
- VERSION = "0.1.16".freeze
2
+ VERSION = "0.1.18".freeze
3
3
  end
@@ -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.16
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-09-22 00:00:00.000000000 Z
11
+ date: 2023-10-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails