metricky 0.3.1 → 0.4.0

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: 00c9f64ffdfcde854adec21097bbee40db3346ae0e29e135515ec369ab2c4125
4
- data.tar.gz: 1a505fad343ef588d47a9ac91031aa08742ebe83b391950867e0e245d33668f9
3
+ metadata.gz: 2ba909df61c99a49ddea9e6bc914eb941796f18c38443e6becdecf3766542522
4
+ data.tar.gz: 3c69b7adda470fe9d06e7fb0383213d988b191a0224b3be4d6cf1518c450887a
5
5
  SHA512:
6
- metadata.gz: 28785bf4d28eada869bc59818f86309bf1e0dd1bf9171eda4bdd5dcf902f782273198023086b672dd49500c79ac1670b5eec17c371903478e41b7bb39b051e71
7
- data.tar.gz: 3ba646a2f5b421496652e43b4591ae7029769e87501dc91fa476ef99f2d825830e1cc75cbfc59310e7731e3282557899657b5ffd3d86079ea67413ca2e7da63e
6
+ metadata.gz: 924c1ded4febd716dbbd9d01885581668cd3dfb014595fb630efe2e5c92d3e280fdc7b04ad87d5797fc528b2f639fc67585f392755cf1dfd68046a36c8fb9d62
7
+ data.tar.gz: 25309a6bd7a3836ab5a6b69b85301c958c64023638a0d3b4100b9c8fd117d263a1376cd13dedb7ad728bbfe6ac2c0d397a17255d5f30dd7a9a59d139fc8d9594
data/README.md CHANGED
@@ -7,6 +7,9 @@ Make this in Ruby:
7
7
 
8
8
  <img src="https://i.imgur.com/PQhFyAE.png" alt="Metricky example">
9
9
 
10
+ ## Generate it
11
+
12
+ `rails g metricky:metric User --scope User --type :count --period :day`
10
13
  In your view where you want to display the metric:
11
14
 
12
15
  ```erbruby
@@ -29,7 +32,7 @@ class UsersMetric < Metricky::Base
29
32
  :id
30
33
  end
31
34
 
32
- def trend
35
+ def period
33
36
  :day
34
37
  end
35
38
  end
@@ -72,12 +75,12 @@ def columns
72
75
  end
73
76
  ```
74
77
 
75
- ### Grouping
78
+ ### Grouping by date
76
79
 
77
- In your metric, define what trend:
80
+ In your metric, define what period:
78
81
 
79
82
  ```ruby
80
- def trend
83
+ def period
81
84
  :day
82
85
  end
83
86
  ```
@@ -87,7 +90,7 @@ This can be any one of `Groupdate::PERIODS`
87
90
  Define what column should be used:
88
91
 
89
92
  ```ruby
90
- def trend_column
93
+ def period_column
91
94
  :created_at
92
95
  end
93
96
  ```
@@ -18,6 +18,7 @@ module Metricky
18
18
  end
19
19
 
20
20
  private
21
+
21
22
  def file_name # :doc:
22
23
  @_file_name ||= super.sub(/_metric\z/i, "")
23
24
  end
data/lib/metricky/base.rb CHANGED
@@ -123,6 +123,11 @@ module Metricky
123
123
  # [:second, :minute, :hour, :day, :week, :month, :quarter, :year, :day_of_week,
124
124
  # :hour_of_day, :minute_of_hour, :day_of_month, :month_of_year]
125
125
  def trend
126
+ ActiveSupport::Deprecation.warn('Use period instead')
127
+ period
128
+ end
129
+
130
+ def period
126
131
  nil
127
132
  end
128
133
 
@@ -132,18 +137,23 @@ module Metricky
132
137
  end
133
138
 
134
139
  # What column to specify for the trend calculation. Normally `created_at`
135
- def trend_column
140
+ def period_column
136
141
  'created_at'
137
142
  end
138
143
 
144
+ def trend_column
145
+ ActiveSupport::Deprecation.warn('Use period_column instead')
146
+ period_column
147
+ end
148
+
139
149
  def range
140
150
  params.dig(form_name, :range)
141
151
  end
142
152
 
143
153
  private
144
154
 
145
- def trend?
146
- trend.present?
155
+ def period?
156
+ period.present?
147
157
  end
148
158
 
149
159
  def assets
@@ -152,16 +162,16 @@ module Metricky
152
162
  else
153
163
  @query = scope
154
164
  end
155
- if trend? && valid_trend?
165
+ if period? && valid_period?
156
166
  @query = @query.group_by_period(trend, trend_column)
157
167
  end
158
168
  @query = @query.send(type, *columns)
159
169
  @query
160
170
  end
161
171
 
162
- def valid_trend?
163
- return true if Groupdate::PERIODS.include?(trend.to_sym)
164
- raise NameError, "trend must be one of #{Groupdate::PERIODS}. It is #{trend}."
172
+ def valid_period?
173
+ return true if Groupdate::PERIODS.include?(period.to_sym)
174
+ raise NameError, "period must be one of #{Groupdate::PERIODS}. It is #{period}."
165
175
  end
166
176
 
167
177
  def check_type
@@ -1,3 +1,3 @@
1
1
  module Metricky
2
- VERSION = '0.3.1'
2
+ VERSION = '0.4.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metricky
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josh Brody