Class: Graphite::Graph

Inherits:
Base
  • Object
show all
Defined in:
lib/graphite/graph.rb

Direct Known Subclasses

MyGraph, UserGraph

Instance Attribute Summary collapse

Class Method Summary collapse

Methods inherited from Base

authenticate, connection, get, set_connection

Instance Attribute Details

#allow_childrenObject

Returns the value of attribute allow_children.



5
6
7
# File 'lib/graphite/graph.rb', line 5

def allow_children
  @allow_children
end

#idObject

Returns the value of attribute id.



5
6
7
# File 'lib/graphite/graph.rb', line 5

def id
  @id
end

#leafObject

Returns the value of attribute leaf.



5
6
7
# File 'lib/graphite/graph.rb', line 5

def leaf
  @leaf
end

#nameObject

Returns the value of attribute name.



5
6
7
# File 'lib/graphite/graph.rb', line 5

def name
  @name
end

#urlObject

Returns the value of attribute url.



5
6
7
# File 'lib/graphite/graph.rb', line 5

def url
  @url
end

Class Method Details

.descend_to_leaf(query, path) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/graphite/graph.rb', line 20

def self.descend_to_leaf(query,path)
  result = []
  self.find_by_query_and_path(query,path).each do |graph|
    if graph.leaf 
      return graph 
    else
      result << self.descend_to_leaf(graph.name + "*",graph.name)
    end        
  end
  return result
end

.find_all_by_query(query) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/graphite/graph.rb', line 32

def self.find_all_by_query(query)
  result = []
  self.find_by_query_and_path(query,"").each do |graph|        
    result << self.descend_to_leaf(graph.name + "*",graph.name)
  end
  return result.flatten
end

.find_by_query_and_path(query, path) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/graphite/graph.rb', line 7

def self.find_by_query_and_path(query,path)
  graph_type = "#{self}" == "Graphite::MyGraph" ? "mygraph" : "usergraph"
  return JSON.parse(self.get("/browser/#{graph_type}/",{:format => "treejson",:query => query,:path =>path}).body).map do |graphic_hash|
    graphic = MyGraph.new
    graphic.url            = graphic_hash["graphUrl"]
    graphic.name           = graphic_hash["id"]
    graphic.leaf           = graphic_hash["leaf"] == 1
    graphic.allow_children = graphic_hash["allowChildren"] == 1
    graphic
  end
end