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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ae35b0a41cb186989dbb8f76fb8dbfa11604782e6b795fca0ac5e50e66bdd3fa
4
- data.tar.gz: 88b9bb3f9cf86b143d997502d0ae997606652d813541259c684d76c7c379b40d
3
+ metadata.gz: 9ab70e84303c1c0c272c26be3b64a6933d970b48899776df943d279532b58873
4
+ data.tar.gz: f9171035e94d58535a2a59097aa14008a1dc997583c677ffe70e96990a2a7361
5
5
  SHA512:
6
- metadata.gz: a6239fb1c253b895b3bf35f640fde0f600cc853f9348839108536abf2eed887c71c763b1c1ebb71fa4d2eff07bb77b953732641edb4dde3f271127d25d76287e
7
- data.tar.gz: fde9049ba6c66da3901eb99352b3e938130a46e8a24e85c42a04a92c4c641188e112299ea2882b632fe3f6d833f300d9bc8f7aa52928a69b4df7653377af268f
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
@@ -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
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Scopiform
2
- VERSION = '0.2.6'.freeze
2
+ VERSION = '0.2.7'.freeze
3
3
  end
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.6
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-01 00:00:00.000000000 Z
11
+ date: 2021-03-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord