metricky 0.8.0 → 0.8.2

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: 362f2f40e07645963b83935211c9ab8c222db9cb9064c099dd8b466597be2b08
4
- data.tar.gz: 5a882ce98adecc050b1f3398935b26b09d961d67d98db24b5a018a3f3c43d65f
3
+ metadata.gz: ba9f360352ce74897a0d14441895c362c20f030d660f3a3317cc1499c8889938
4
+ data.tar.gz: 33a086fc39c12b532b607ab8a5a087655a6a62c01a673d3da5f8e1b99724f152
5
5
  SHA512:
6
- metadata.gz: f3f72bad0f1523a606e27244780c1b43e739fd846e5b393c4ab1bac1a2c4a8b8b2ca63cd23a01f51a7ff7a710faa624b1236dff0b0d1cc613707459ccec3967e
7
- data.tar.gz: 9fa0ad994b4c4558f95eecb24ba9bf05ee42f19fc2805771900716925433f1b818e528f6887e2cff0b0f8ba5ab884cb85fd10541fdd482e6937aa9ef0f59103c
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 (:count, :max, :min, :sum, :average)"
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")
@@ -47,5 +47,10 @@ class <%= class_name %>Metric < ApplicationMetric
47
47
  # def form?
48
48
  # false
49
49
  # end
50
+
51
+ # ==> Change the collection label on ranges
52
+ # def collection_label(range_thing)
53
+ # "Born #{range_thing.label}"
54
+ # end
50
55
  end
51
56
  <% end -%>
data/lib/metricky/base.rb CHANGED
@@ -139,6 +139,9 @@ module Metricky
139
139
  @query
140
140
  end
141
141
 
142
+ def h
143
+ @h ||= ActionController::Base.helpers
144
+ end
142
145
 
143
146
  def format_value(value)
144
147
  value
@@ -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.label, key] }
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
@@ -1,3 +1,3 @@
1
1
  module Metricky
2
- VERSION = '0.8.0'
2
+ VERSION = '0.8.2'
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.8.0
4
+ version: 0.8.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josh Brody