scopiform 0.2.6 → 0.2.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/scopiform/association_scopes.rb +13 -0
- data/lib/scopiform/common_scopes.rb +9 -0
- data/lib/scopiform/filters.rb +9 -0
- data/lib/scopiform/utilities.rb +4 -0
- data/lib/scopiform/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9ab70e84303c1c0c272c26be3b64a6933d970b48899776df943d279532b58873
|
4
|
+
data.tar.gz: f9171035e94d58535a2a59097aa14008a1dc997583c677ffe70e96990a2a7361
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8d35b11ef72e806d0c2620a90fbd5785ad0af0c3b449955cd524783e64cdba72ea4c25ca537cbf1e37585427cd496521191e8de448c02c1cbccfe4d35d3ba11c
|
7
|
+
data.tar.gz: 9287384da79e115b42ea7a0e7971944c97500867e2c987bcffe8fb8f92eae2ab873b6e2278cfa5992d44c263b27988cafd8153571885cc8abea8a88a5df42723
|
@@ -44,6 +44,19 @@ module Scopiform
|
|
44
44
|
argument_type: :hash,
|
45
45
|
type: :sort
|
46
46
|
)
|
47
|
+
|
48
|
+
# Grouping
|
49
|
+
auto_scope_add(
|
50
|
+
association.name,
|
51
|
+
proc { |value, ctx: nil|
|
52
|
+
next all unless Utilities.truthy_hash(value)
|
53
|
+
|
54
|
+
Utilities.association_scope(self, association, :apply_groupings, value, ctx: ctx)
|
55
|
+
},
|
56
|
+
prefix: 'group_by_',
|
57
|
+
argument_type: :hash,
|
58
|
+
type: :group
|
59
|
+
)
|
47
60
|
end
|
48
61
|
end
|
49
62
|
end
|
@@ -40,6 +40,15 @@ module Scopiform
|
|
40
40
|
argument_type: :string,
|
41
41
|
type: :sort
|
42
42
|
)
|
43
|
+
|
44
|
+
# Grouping
|
45
|
+
auto_scope_add(
|
46
|
+
name,
|
47
|
+
proc { |value = true, ctx: nil, **| group(scopiform_arel(ctx)[name_sym]) if value },
|
48
|
+
prefix: 'group_by_',
|
49
|
+
argument_type: :boolean,
|
50
|
+
type: :group
|
51
|
+
)
|
43
52
|
end
|
44
53
|
end
|
45
54
|
end
|
data/lib/scopiform/filters.rb
CHANGED
@@ -16,6 +16,10 @@ module Scopiform
|
|
16
16
|
sorts_hash.keys.inject(injecting) { |out, sort_name| resolve_sort(out, sort_name, sorts_hash[sort_name], ctx: ctx) }
|
17
17
|
end
|
18
18
|
|
19
|
+
def apply_groupings(groupings_hash, injecting = all, ctx: nil)
|
20
|
+
groupings_hash.keys.inject(injecting) { |out, grouping_name| resolve_grouping(out, grouping_name, groupings_hash[grouping_name], ctx: ctx) }
|
21
|
+
end
|
22
|
+
|
19
23
|
private
|
20
24
|
|
21
25
|
def resolve_filter(out, filter_name, filter_argument, ctx:)
|
@@ -37,6 +41,11 @@ module Scopiform
|
|
37
41
|
method_name = "sort_by_#{sort_name}"
|
38
42
|
out.send(method_name, sort_argument, ctx: ctx)
|
39
43
|
end
|
44
|
+
|
45
|
+
def resolve_grouping(out, group_name, group_argument, ctx:)
|
46
|
+
method_name = "group_by_#{group_name}"
|
47
|
+
out.send(method_name, group_argument, ctx: ctx)
|
48
|
+
end
|
40
49
|
end
|
41
50
|
end
|
42
51
|
end
|
data/lib/scopiform/utilities.rb
CHANGED
@@ -26,5 +26,9 @@ module Scopiform
|
|
26
26
|
ctx.scopes.reduce(active_record.all.merge(applied)) { |chain, scope| chain.merge(scope) }
|
27
27
|
end
|
28
28
|
end
|
29
|
+
|
30
|
+
def self.truthy_hash(hash)
|
31
|
+
hash.values.find { |value| value.is_a?(Hash) ? truthy_hash(value) : value.present? }
|
32
|
+
end
|
29
33
|
end
|
30
34
|
end
|
data/lib/scopiform/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scopiform
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- jayce.pulsipher
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-03-
|
11
|
+
date: 2021-03-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|