Module: Metricky::Helper
- Defined in:
- lib/metricky/helper.rb
Instance Method Summary collapse
- #metric_form_for(metric) ⇒ Object
- #metrick_path(metric, options = {}) ⇒ Object
- #metricky_chart(metric, options = {}) ⇒ Object
- #render_metric(metric_name, options = {}) ⇒ Object
Instance Method Details
#metric_form_for(metric) ⇒ Object
3 4 5 6 7 |
# File 'lib/metricky/helper.rb', line 3 def metric_form_for(metric) form_for("#{request.path}", as: metric.form_name.to_sym, method: :get) do |f| yield(f) end end |
#metrick_path(metric, options = {}) ⇒ Object
9 10 11 |
# File 'lib/metricky/helper.rb', line 9 def metrick_path(metric, = {}) metricky.metric_path(name: metric.name.underscore, query: request.query_parameters, options: ) end |
#metricky_chart(metric, options = {}) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/metricky/helper.rb', line 30 def metricky_chart(metric, = {}) if metric.json? send(metric.chart, metrick_path(metric, )) else send(metric.chart, metric.results, ) end end |
#render_metric(metric_name, options = {}) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/metricky/helper.rb', line 13 def render_metric(metric_name, = {}) if metric_name.is_a?(String) || metric_name.is_a?(Symbol) metric_name = metric_name.to_s if metric_name.end_with?("Metric") metric = metric_name.safe_constantize else klass_name = "#{metric_name.to_s}Metric".camelize metric = "#{klass_name}".safe_constantize end raise NameError, "#{metric_name} does not exist" unless metric else metric = metric_name end metric = metric.new(params, ) render metric, metric: metric end |