statisfy 0.0.4 → 0.0.5

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b0232129b80c1b67a7e31c77256fcfea55d199e8bddb41d5acc75738290b54ed
4
- data.tar.gz: f9172db49c79f90d71e49907220db46772991bacda7356eac9dea539e900b115
3
+ metadata.gz: b5d8c7561ef32841eadac25ae7b662fce6ef93d5979b2c0a1c5945d1c608dc09
4
+ data.tar.gz: 480b87c6c4134b0cc0f16ba509920530067c3b7d3b1de8fbfa85ec2c6a381344
5
5
  SHA512:
6
- metadata.gz: 1a7329d1ccd0da87a4eee455a885dc46b8e6bbcc24f1805348b77558114b8d946430ea33a443b432aba59f4e4a60314b4b53336539e1240e4afaffe4b1d33b51
7
- data.tar.gz: 5cc4383205544ea34da8bf25b1683237f7f89e241dc393376cc1d4ac0f478ecf2cc2bfc91e885db4d0b89d2337af7adc9eeea30766b253f41949cdbfc4287d41
6
+ metadata.gz: 141624d3043afab8642a513f1a93cf1a378d2412ae75f68154c4fa720ff86597b9fca54ccd13e3aa76c3414aacb462a7cdb647628f7db970aee7fae500a7c97c
7
+ data.tar.gz: e71caf7bdfee33bc954ede9ca8bd1a09b1fc20d1336bc0f7786d24d2cb27ceabbb7a9e362f4b06ff0b8c42ca65de9e0b3887501c7002cf7567283d050d0aecf2
@@ -0,0 +1,34 @@
1
+ require "ostruct"
2
+
3
+ module Statisfy
4
+ module Model
5
+ def self.included(klass)
6
+ klass.extend(ClassMethods)
7
+ klass.class_eval do
8
+ @statisfy = {}
9
+ end
10
+ end
11
+
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
16
+
17
+ class_name = params[:as].to_s.camelize
18
+
19
+ eval <<-RUBY, binding, __FILE__, __LINE__ + 1
20
+ class ::Statisfy::#{class_name}
21
+ include Statisfy::Counter
22
+
23
+ #{source || "count(#{params})"}
24
+ end
25
+ RUBY
26
+ class_eval <<-RUBY, __FILE__, __LINE__ + 1
27
+ def self.#{params[:as]}
28
+ ::Statisfy::#{class_name}
29
+ end
30
+ RUBY
31
+ end
32
+ end
33
+ end
34
+ end
data/lib/statisfy.rb CHANGED
@@ -4,6 +4,7 @@ require_relative "statisfy/configuration"
4
4
  require_relative "statisfy/counter"
5
5
  require_relative "statisfy/aggregate"
6
6
  require_relative "statisfy/monthly"
7
+ require_relative "statisfy/model"
7
8
 
8
9
  module Statisfy
9
10
  class Error < StandardError; 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.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michaël Villeneuve
@@ -119,6 +119,7 @@ files:
119
119
  - lib/statisfy/aggregate.rb
120
120
  - lib/statisfy/configuration.rb
121
121
  - lib/statisfy/counter.rb
122
+ - lib/statisfy/model.rb
122
123
  - lib/statisfy/monthly.rb
123
124
  - lib/statisfy/subscriber.rb
124
125
  homepage: https://github.com/Michaelvilleneuve/statisfy