Module: Merb::ChefServerSlice::SearchHelper

Defined in:
app/helpers/search_helper.rb

Instance Method Summary collapse

Instance Method Details

#ohai_walk(path) ⇒ Object



16
17
18
19
20
21
22
# File 'app/helpers/search_helper.rb', line 16

def ohai_walk(path)
  unless path[0]
    @@ohai.to_json
  else
    ohai_walk_r(@@ohai, path)
  end
end

#ohai_walk_r(ohai, path) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/helpers/search_helper.rb', line 24

def ohai_walk_r(ohai, path)
  hop = (ohai.is_a?(Array) ? path.shift.to_i : path.shift)
  if ohai[hop]
    if path[0]
      ohai_walk_r(ohai[hop], path)
    else
      ohai[hop].to_json
    end
  else
    nil
  end
end

#output_path(attributes) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
# File 'app/helpers/search_helper.rb', line 4

def output_path(attributes)
  res = Hash.new
  attributes.each do |path|
    parts = path.split("/")
    unless parts[0].nil?
      parts.shift if parts[0].length == 0
    end
    res[path] = ohai_walk(parts)
  end
  res
end