croods 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b9fa939ee66088adb051cc63ee6f9cfc1206da7674dd6f2c48c524ea0ca8b931
|
4
|
+
data.tar.gz: 9e9722e961a8b24760106965a385a5aad1a89d9b85369243d3497c2c3fc33784
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 65565603371e3e5d46d3c8f412af157bd4e50ca2c1f6afc57a3577f4dd77f294bd63624c7f02585973214ff978d7312367d520916f7497c4f29f49f582b28f1b
|
7
|
+
data.tar.gz: 3d0f2872653a07a3edb49cdb3cc368e34eb153826a5066099ed250400000613ea128bbbf5dac4cc3563fffe87f67b94ac82d2854a8a30004010d4f6d200b9be5
|
@@ -13,11 +13,17 @@ module Croods
|
|
13
13
|
paginate(list.send(resource.page_method_name, page_param))
|
14
14
|
end
|
15
15
|
|
16
|
-
def
|
17
|
-
list
|
18
|
-
.
|
19
|
-
|
16
|
+
def sort(list)
|
17
|
+
if list.respond_to? resource.sort_by
|
18
|
+
list.public_send(resource.sort_by, params[:order_by], params[:order])
|
19
|
+
else
|
20
|
+
list.order(resource.sort_by)
|
21
|
+
end
|
22
|
+
end
|
20
23
|
|
24
|
+
def collection
|
25
|
+
list = resource.apply_filters(policy_scope(model), params)
|
26
|
+
list = sort(list)
|
21
27
|
list = paginate_collection(list) if page_param.present?
|
22
28
|
|
23
29
|
list
|
@@ -36,7 +36,9 @@ module Croods
|
|
36
36
|
def properties(resource)
|
37
37
|
properties = {}
|
38
38
|
|
39
|
-
resource.pagination_params
|
39
|
+
params = resource.pagination_params + resource.order_params
|
40
|
+
|
41
|
+
params.each do |attribute|
|
40
42
|
properties[attribute.name] = definition(attribute)
|
41
43
|
end
|
42
44
|
|
@@ -3,10 +3,26 @@
|
|
3
3
|
module Croods
|
4
4
|
module Resource
|
5
5
|
module Sorting
|
6
|
+
def order_by_attribute
|
7
|
+
@order_by_attribute ||= Croods::Attribute.new(
|
8
|
+
'order_by', :string, null: true
|
9
|
+
)
|
10
|
+
end
|
11
|
+
|
12
|
+
def order_attribute
|
13
|
+
@order_attribute ||= Croods::Attribute.new(
|
14
|
+
'order', :string, null: true
|
15
|
+
)
|
16
|
+
end
|
17
|
+
|
18
|
+
def order_params
|
19
|
+
@order_params ||= [order_by_attribute, order_attribute]
|
20
|
+
end
|
21
|
+
|
6
22
|
def sort_by(attribute = nil)
|
7
23
|
return @sort_by ||= :created_at unless attribute
|
8
24
|
|
9
|
-
@sort_by
|
25
|
+
@sort_by ||= attribute
|
10
26
|
end
|
11
27
|
end
|
12
28
|
end
|
data/lib/croods/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: croods
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Weinmann
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-10-
|
11
|
+
date: 2020-10-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: api-pagination
|