statisfy 0.0.5 → 0.0.7

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/statisfy/model.rb +10 -6
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b5d8c7561ef32841eadac25ae7b662fce6ef93d5979b2c0a1c5945d1c608dc09
4
- data.tar.gz: 480b87c6c4134b0cc0f16ba509920530067c3b7d3b1de8fbfa85ec2c6a381344
3
+ metadata.gz: 1b485c63cd06fb497bc3b0426082f221b99e78ae5d95573fe4b747c0e0ddec5d
4
+ data.tar.gz: 930b4574ad28f2ad09b85fe8ff3c96075bbcbf4585af7520526ba24fa77e6f21
5
5
  SHA512:
6
- metadata.gz: 141624d3043afab8642a513f1a93cf1a378d2412ae75f68154c4fa720ff86597b9fca54ccd13e3aa76c3414aacb462a7cdb647628f7db970aee7fae500a7c97c
7
- data.tar.gz: e71caf7bdfee33bc954ede9ca8bd1a09b1fc20d1336bc0f7786d24d2cb27ceabbb7a9e362f4b06ff0b8c42ca65de9e0b3887501c7002cf7567283d050d0aecf2
6
+ metadata.gz: 4da2848076d5caf49a8c5e5084763bd5c4625b28bbcb0bb59ae7710382f558667fddbe783507fb4bb1221ba5ce9239e478946317dfbcf55963139137009b5ce7
7
+ data.tar.gz: 1b1e517c2f3676253909cc2583440bdb22b84eb19baa46177c6b4572aa2c6d27ca94fe1cbfee2495e805051cf0fcdf950c69c837af8bd6ad80dd0e0e0a7c1d49
@@ -10,24 +10,28 @@ module Statisfy
10
10
  end
11
11
 
12
12
  module ClassMethods
13
- def count(params)
14
- a_bloc = params.fetch(:scopes, nil) || params.fetch(:uniq_by, nil) || params.fetch(:if, nil)
15
- source = a_bloc&.source
13
+ def statisfy_count(params)
14
+ raise ArgumentError, "Missing :as parameter" unless params[:as]
16
15
 
17
16
  class_name = params[:as].to_s.camelize
18
17
 
19
18
  eval <<-RUBY, binding, __FILE__, __LINE__ + 1
20
19
  class ::Statisfy::#{class_name}
21
- include Statisfy::Counter
22
-
23
- #{source || "count(#{params})"}
20
+ include Statisfy::#{params[:type] == :aggregate ? "Aggregate" : "Counter"}
24
21
  end
25
22
  RUBY
23
+
26
24
  class_eval <<-RUBY, __FILE__, __LINE__ + 1
27
25
  def self.#{params[:as]}
28
26
  ::Statisfy::#{class_name}
29
27
  end
30
28
  RUBY
29
+
30
+ "::Statisfy::#{class_name}".constantize.send(:count, **params)
31
+ end
32
+
33
+ def statisfy_aggregate(params)
34
+ statisfy_count(params.merge(type: :aggregate))
31
35
  end
32
36
  end
33
37
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: statisfy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michaël Villeneuve