effective_resources 0.4.10 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/models/effective/resources/relation.rb +7 -6
- data/lib/effective_resources/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e5800f90d584446cae530052c580fc7d43e690a7
|
4
|
+
data.tar.gz: e5cb47b3fea2a63222a5bbb6f06ca417372b8b3d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bdb4b94bc22efb2b723df96467b5d7f03c467fd9e173cbeea8ca64edb2e45eba98bb011f5c69fe92d2e997656b614e9593a36179dcc31e91a6e6e2a7d1168a5a
|
7
|
+
data.tar.gz: e7c659d37e240c593c751fee96270c06aef5983b028efdfb5585857d5cd1ca98c06913a5aeb14ca7354ddc216f8f12ecc361c277dfc152c1655c8384c04505c6
|
@@ -9,7 +9,7 @@ module Effective
|
|
9
9
|
# name: sort by this column, or this relation
|
10
10
|
# sort: when a symbol or boolean, this is the relation's column to sort by
|
11
11
|
|
12
|
-
def order(name, direction = :asc, as: nil, sort: nil, sql_column: nil)
|
12
|
+
def order(name, direction = :asc, as: nil, sort: nil, sql_column: nil, limit: nil, reorder: false)
|
13
13
|
raise 'expected relation to be present' unless relation
|
14
14
|
|
15
15
|
sql_column ||= sql_column(name)
|
@@ -17,23 +17,24 @@ module Effective
|
|
17
17
|
|
18
18
|
association = associated(name)
|
19
19
|
sql_direction = sql_direction(direction)
|
20
|
+
@relation = relation.reorder(nil) if reorder
|
20
21
|
|
21
22
|
case sql_type
|
22
23
|
when :belongs_to
|
23
24
|
relation
|
24
25
|
.order("#{is_null(sql_column)} ASC")
|
25
|
-
.order(order_by_associated_conditions(association, sort: sort, direction: direction))
|
26
|
+
.order(order_by_associated_conditions(association, sort: sort, direction: direction, limit: limit))
|
26
27
|
when :belongs_to_polymorphic
|
27
28
|
relation
|
28
29
|
.order("#{sql_column.sub('_id', '_type')} #{sql_direction}")
|
29
30
|
.order("#{sql_column} #{sql_direction}")
|
30
31
|
when :has_and_belongs_to_many, :has_many, :has_one
|
31
32
|
relation
|
32
|
-
.order(order_by_associated_conditions(association, sort: sort, direction: direction))
|
33
|
+
.order(order_by_associated_conditions(association, sort: sort, direction: direction, limit: limit))
|
33
34
|
.order("#{sql_column(klass.primary_key)} #{sql_direction}")
|
34
35
|
when :effective_addresses
|
35
36
|
relation
|
36
|
-
.order(order_by_associated_conditions(associated(:addresses), sort: sort, direction: direction))
|
37
|
+
.order(order_by_associated_conditions(associated(:addresses), sort: sort, direction: direction, limit: limit))
|
37
38
|
.order("#{sql_column(klass.primary_key)} #{sql_direction}")
|
38
39
|
when :effective_roles
|
39
40
|
relation.order("#{sql_column(:roles_mask)} #{sql_direction}")
|
@@ -219,13 +220,13 @@ module Effective
|
|
219
220
|
"#{key} IN (#{(keys.uniq.compact.presence || [0]).join(',')})"
|
220
221
|
end
|
221
222
|
|
222
|
-
def order_by_associated_conditions(association, sort: nil, direction: :asc)
|
223
|
+
def order_by_associated_conditions(association, sort: nil, direction: :asc, limit: nil)
|
223
224
|
resource = Effective::Resource.new(association)
|
224
225
|
|
225
226
|
# Order the target model for its matching records / keys
|
226
227
|
sort_column = (sort unless sort == true) || resource.sort_column
|
227
228
|
|
228
|
-
relation = resource.
|
229
|
+
relation = resource.order(sort_column, direction, limit: limit, reorder: true).limit([limit, 1000].compact.min)
|
229
230
|
|
230
231
|
if association.options[:as] # polymorphic
|
231
232
|
relation = relation.where(association.type => klass.name)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: effective_resources
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Code and Effect
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-10-
|
11
|
+
date: 2017-10-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|