Class: GDash::Dashboard

Inherits:
Object
  • Object
show all
Defined in:
lib/gdash/dashboard.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(short_name, dir, options = {}) ⇒ Dashboard

Returns a new instance of Dashboard.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/gdash/dashboard.rb', line 5

def initialize(short_name, dir, options={})
  raise "Cannot find dashboard directory #{dir}" unless File.directory?(dir)

  @properties = {:graph_width => nil,
                 :graph_height => nil,
                 :graph_from => nil,
                 :graph_until => nil}

  @properties[:short_name] = short_name
  @properties[:directory] = File.join(dir, short_name)
  @properties[:yaml] = File.join(dir, short_name, "dash.yaml")

  raise "Cannot find YAML file #{yaml}" unless File.exist?(yaml)

  @properties.merge!(YAML.load_file(yaml))

  # Properties defined in dashboard config file are overridden when given on initialization
  @properties[:graph_width] = options.delete(:width) || graph_width
  @properties[:graph_height] = options.delete(:height) || graph_height
  @properties[:graph_from] = options.delete(:from) || graph_from
  @properties[:graph_until] = options.delete(:until) || graph_until
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object



43
44
45
46
47
48
49
# File 'lib/gdash/dashboard.rb', line 43

def method_missing(method, *args)
  if properties.include?(method)
    properties[method]
  else
    super
  end
end

Instance Attribute Details

#propertiesObject

Returns the value of attribute properties.



3
4
5
# File 'lib/gdash/dashboard.rb', line 3

def properties
  @properties
end

Instance Method Details

#graphs(options = {}) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/gdash/dashboard.rb', line 28

def graphs(options={})
  options[:width] ||= graph_width
  options[:height] ||= graph_height
  options[:from] ||= graph_from
  options[:until] ||= graph_until

  graphs = Dir.entries(directory).select{|f| f.match(/\.graph$/)}

  overrides = options.reject { |k,v| v.nil? }

  graphs.sort.map do |graph|
    {:name => File.basename(graph, ".graph"), :graphite => GraphiteGraph.new(File.join(directory, graph), overrides)}
  end
end