Sha256: e23643ec6f699c75d3d120299a524c35f9a8068d216e46ce2a9739f62e99ef48

Contents?: true

Size: 1.6 KB

Versions: 6

Compression:

Stored size: 1.6 KB

Contents

#
# Author:: Adam Jacob (<adam@opscode.com>)
# Copyright:: Copyright (c) 2008 Opscode, Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# 
#     http://www.apache.org/licenses/LICENSE-2.0
# 
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

require 'extlib'

class Chef
  class Search
    class Result

      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

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

      # Serialize this object as a hash 
      def to_json(*a)
        result = {
          'json_class' => self.class.name,
          'results' => @internal
        }
        result.to_json(*a)
      end
      
      # Create a Chef::Search::Result from JSON
      def self.json_create(o)
        result = self.new
        o['results'].each do |k,v|
          result[k] = v
        end
        result
      end
    end
  end
end


Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
chef-0.7.16 lib/chef/search/result.rb
giraffesoft-chef-0.7.16 lib/chef/search/result.rb
giraffesoft-chef-0.7.15 lib/chef/search/result.rb
chef-0.7.14 lib/chef/search/result.rb
chef-0.7.12 lib/chef/search/result.rb
chef-0.7.10 lib/chef/search/result.rb