class GraphiteDashboardApi::Graph

Constants

PROPS

Public Class Methods

new(title = nil, &block) click to toggle source
# File lib/graphite-dashboard-api/graph.rb, line 23
def initialize(title = nil, &block)
  @title = title
  @targets = []
  @compact_leading = false # this is tweaking stuff
  @extra_options = {}
  instance_eval(&block) if block
end

Public Instance Methods

default_title() click to toggle source

This is probably an over simplification TODO

# File lib/graphite-dashboard-api/graph.rb, line 36
def default_title
  @targets.first
end
from_hash!(hash) click to toggle source
# File lib/graphite-dashboard-api/graph.rb, line 76
def from_hash!(hash)
  @title = hash['title']
  PROPS.each do |k|
    value = hash[k.to_s]
    instance_variable_set("@#{k}".to_sym, value) if value
  end
  if hash['target']
    hash['target'].each do |target|
      @targets << target
    end
  end
  std_options = ['title', 'target', PROPS].map { |k| k.to_s }
  extra_options_from_hash!(std_options, hash)
  self
end
leading_entries() click to toggle source
# File lib/graphite-dashboard-api/graph.rb, line 50
def leading_entries
  if @compact_leading
    leading_entries = target_encode
  else
    leading_entries = @targets
  end
end
render_options(default_options) click to toggle source
# File lib/graphite-dashboard-api/graph.rb, line 40
def render_options(default_options)
  opts = []
  PROPS.each do |k|
    v = instance_variable_get "@#{k}".to_sym
    v ||= default_options[k.to_s]
    opts << "#{k.to_s}=#{v}" if v
  end
  opts.join('&')
end
target_encode() click to toggle source
# File lib/graphite-dashboard-api/graph.rb, line 58
def target_encode
  @targets.map do |target|
    'target=' + target
  end.join('&')
end
to_hash() click to toggle source
# File lib/graphite-dashboard-api/graph.rb, line 64
def to_hash
  hash = {}
  hash['title'] = @title if @title
  PROPS.each do |k|
    v = instance_variable_get "@#{k}".to_sym
    hash[k.to_s] = v if v
  end
  hash['target'] = @targets
  hash.merge!(extra_options_to_hash)
  hash
end
url(default_options) click to toggle source
# File lib/graphite-dashboard-api/graph.rb, line 31
def url(default_options)
  '/render?' + render_options(default_options) + '&' + target_encode + "&title=#{@title || default_title}"
end