metricky 0.8.0 → 0.8.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +22 -0
- data/lib/generators/metricky/metric_generator.rb +4 -3
- data/lib/generators/metricky/templates/metric.rb.tt +5 -0
- data/lib/metricky/base.rb +3 -0
- data/lib/metricky/ranges.rb +5 -1
- data/lib/metricky/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ba9f360352ce74897a0d14441895c362c20f030d660f3a3317cc1499c8889938
|
4
|
+
data.tar.gz: 33a086fc39c12b532b607ab8a5a087655a6a62c01a673d3da5f8e1b99724f152
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5aa3e090e3e978c9ab99aff4beb8c0037d03829ef78e4bc02c4136ab5a8a599779265b8c90079c13c70299569819afd2e8218e39943d095d635293acc741bc05
|
7
|
+
data.tar.gz: 7942700ad381ac944c887ecadea0f91f945a9c8b19f196a1594a8eb3f92e3cb81320c86a5f7c096369229931c82aed1669e24c7001378b5d233fecb1bfed696e
|
data/README.md
CHANGED
@@ -176,6 +176,28 @@ class TotalUsersMetric < ApplicationMetric
|
|
176
176
|
end
|
177
177
|
```
|
178
178
|
|
179
|
+
#### Customizing the label
|
180
|
+
|
181
|
+
Use `collection_label`
|
182
|
+
|
183
|
+
```ruby
|
184
|
+
class TotalUsersMetric < ApplicationMetric
|
185
|
+
def collection_label(range_thing)
|
186
|
+
"Born #{range_thing.value.call}"
|
187
|
+
end
|
188
|
+
end
|
189
|
+
```
|
190
|
+
|
191
|
+
Need helpers? `h`
|
192
|
+
|
193
|
+
```
|
194
|
+
class TotalUsersMetric < ApplicationMetric
|
195
|
+
def collection_label(range_thing)
|
196
|
+
"Born #{h.time_ago_in_words(range_thing.value.call)}"
|
197
|
+
end
|
198
|
+
end
|
199
|
+
```
|
200
|
+
|
179
201
|
### Partial
|
180
202
|
|
181
203
|
In your metric, define the partial path:
|
@@ -4,9 +4,10 @@ module Metricky
|
|
4
4
|
source_root File.expand_path("templates", __dir__)
|
5
5
|
check_class_collision suffix: "Metric"
|
6
6
|
|
7
|
-
class_option :scope, type: :string, aliases: %i(--scope), default: '', desc: "What class or scoped class this metric pulls from"
|
8
|
-
class_option :type, type: :string, aliases: %i(--type), default: ':count', desc: "What type of metric
|
9
|
-
class_option :period, type: :string, default: 'nil', aliases: %i{--period}, desc: "What class or scoped class this metric pulls from"
|
7
|
+
class_option :scope, type: :string, aliases: %i(--scope), default: '', desc: "What class or scoped class this metric pulls from. Required."
|
8
|
+
class_option :type, type: :string, aliases: %i(--type), default: ':count', desc: "What type of metric — one of :count, :max, :min, :sum, :average. Default is :count"
|
9
|
+
class_option :period, type: :string, default: 'nil', aliases: %i{--period}, desc: "What class or scoped class this metric pulls from (optional)"
|
10
|
+
class_option :group, type: :string, default: 'nil', aliases: %i{--group}, desc: "Specify what attribute to group by (optional)"
|
10
11
|
|
11
12
|
def create_metric_file
|
12
13
|
template "metric.rb", File.join("app/metrics", class_path, "#{file_name}_metric.rb")
|
data/lib/metricky/base.rb
CHANGED
data/lib/metricky/ranges.rb
CHANGED
@@ -97,13 +97,17 @@ module Metricky
|
|
97
97
|
'created_at'
|
98
98
|
end
|
99
99
|
|
100
|
+
def collection_label(range_thing)
|
101
|
+
"#{range_thing.label}"
|
102
|
+
end
|
103
|
+
|
100
104
|
def range
|
101
105
|
params.dig(form_name, :range) || default_range_key
|
102
106
|
end
|
103
107
|
|
104
108
|
# Used in the HTML form for the metric as the select options
|
105
109
|
def range_collection
|
106
|
-
ranges.sort_by { |_, range| range.priority }.collect { |key, range_thing| [range_thing
|
110
|
+
ranges.sort_by { |_, range| range.priority }.collect { |key, range_thing| [collection_label(range_thing), key] }
|
107
111
|
end
|
108
112
|
end
|
109
113
|
end
|
data/lib/metricky/version.rb
CHANGED