Class: Chef::Search::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/chef/search/result.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeResult

Returns a new instance of Result.



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/chef/search/result.rb', line 25

def initialize
  proc = lambda do |h,k| 
      newhash = Mash.new(&proc)
      h.each do |pk, pv| 
        rx = /^#{k.to_s}_/ 
        if pk =~ rx 
          newhash[ pk.gsub(rx,'') ] = pv 
        end 
      end 
      newhash 
    end 
  @internal = Mash.new(&proc) 
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(symbol, *args, &block) ⇒ Object



39
40
41
# File 'lib/chef/search/result.rb', line 39

def method_missing(symbol, *args, &block)
  @internal.send(symbol, *args, &block)
end

Class Method Details

.json_create(o) ⇒ Object

Create a Chef::Search::Result from JSON



53
54
55
56
57
58
59
# File 'lib/chef/search/result.rb', line 53

def self.json_create(o)
  result = self.new
  o['results'].each do |k,v|
    result[k] = v
  end
  result
end

Instance Method Details

#to_json(*a) ⇒ Object

Serialize this object as a hash



44
45
46
47
48
49
50
# File 'lib/chef/search/result.rb', line 44

def to_json(*a)
  result = {
    'json_class' => self.class.name,
    'results' => @internal
  }
  result.to_json(*a)
end