# module Chef::DSL::DataQuery

## Chef::DSL::DataQuery¶ ↑

Provides DSL for querying data from the chef-server via search or data bag.

### Public Instance Methods

data_bag(bag) click to toggle source

    # File lib/chef/dsl/data_query.rb, line 47
    def data_bag(bag)
      DataBag.validate_name!(bag.to_s)
      rbag = DataBag.load(bag)
      rbag.keys
    rescue Exception
      Log.error("Failed to list data bag items in data bag: #{bag.inspect}")
      raise
    end

data_bag_item(bag, item) click to toggle source

    # File lib/chef/dsl/data_query.rb, line 56
    def data_bag_item(bag, item)
      DataBag.validate_name!(bag.to_s)
      DataBagItem.validate_id!(item)
      DataBagItem.load(bag, item)
    rescue Exception
      Log.error("Failed to load data bag item: #{bag.inspect} #{item.inspect}")
      raise
    end

search(*args, &block) click to toggle source

    # File lib/chef/dsl/data_query.rb, line 32
    def search(*args, &block)
      # If you pass a block, or have at least the start argument, do raw result parsing
      #
      # Otherwise, do the iteration for the end user
      if Kernel.block_given? || args.length >= 4
        Chef::Search::Query.new.search(*args, &block)
      else
        results = Array.new
        Chef::Search::Query.new.search(*args) do |o|
          results << o
        end
        results
      end
    end