Class: GDash::Dashboard
- Inherits:
-
Object
- Object
- GDash::Dashboard
- Defined in:
- lib/gdash/dashboard.rb
Instance Attribute Summary collapse
-
#properties ⇒ Object
Returns the value of attribute properties.
Instance Method Summary collapse
- #graphs(options = {}) ⇒ Object
-
#initialize(short_name, dir, options = {}) ⇒ Dashboard
constructor
A new instance of Dashboard.
- #method_missing(method, *args) ⇒ Object
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, ={}) 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] = .delete(:width) || graph_width @properties[:graph_height] = .delete(:height) || graph_height @properties[:graph_from] = .delete(:from) || graph_from @properties[:graph_until] = .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
#properties ⇒ Object
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(={}) [:width] ||= graph_width [:height] ||= graph_height [:from] ||= graph_from [:until] ||= graph_until graphs = Dir.entries(directory).select{|f| f.match(/\.graph$/)} overrides = .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 |