Commit 55704845 authored by Paul Asmuth's avatar Paul Asmuth
Browse files

Adds a new DSL method "dashboard"

Previously dashboards were created implicitly (when creating widgets) and one could therefore not pass any options to the dashboard initializer. This commits a new DSL method called "dashboard", which can be used to create a dashboard with options.
parent 4609cff6
Loading
Loading
Loading
Loading
+7 −3
Original line number Diff line number Diff line
@@ -2,7 +2,7 @@ class FnordMetric::Namespace
  
  attr_reader :handlers, :gauges, :opts, :key, :dashboards, :flags

  @@opts = [:event, :gauge, :widget, :set_title, :hide_active_users, :hide_overview]
  @@opts = [:event, :gauge, :widget, :set_title, :hide_active_users, :hide_overview, :dashboard]
  @@multi_gauges = [:timeseries_gauge, :toplist_gauge, :distribution_gauge]

  def initialize(key, opts)
@@ -79,9 +79,9 @@ class FnordMetric::Namespace
    @active_users_available
  end

  def dashboards(name=nil)
  def dashboards(name=nil, opts = {})
    return @dashboards unless name
    dash = FnordMetric::Dashboard.new(:title => name)
    dash = FnordMetric::Dashboard.new(opts.merge(:title => name))
    @dashboards[dash.token.to_s] ||= dash
  end

@@ -138,6 +138,10 @@ class FnordMetric::Namespace
    dashboards(dashboard).add_widget(widget)
  end

  def opt_dashboard(dashboard, opts)
    dashboards(dashboard, opts)
  end

  def build_widget(opts)
    _gauges = [opts[:gauges]].flatten.map{ |g| @gauges.fetch(g) }
    widget_klass = "FnordMetric::#{opts.fetch(:type).to_s.capitalize}Widget"