def find_by(type, filter, single = true, &block)
      nodes = []
      env   = node.chef_environment
      if node.public_send(Inflections.pluralize(type.to_s)).include? filter
        nodes << node
      end
      if !single || nodes.empty?
        search(:node, "#{type}:#{filter} AND chef_environment:#{env}") do |n|
          nodes << n
        end
      end

      if block_given?
        nodes.each { |n| yield n }
      else
        single ? nodes.first : nodes
      end
    end
def find_by(type, filter, single = true, &block)
      nodes = []
      env   = node.chef_environment
      if node.public_send(Inflections.pluralize(type.to_s)).include? filter
        nodes << node
      end
      if !single || nodes.empty?
        search(:node, "#{type}:#{filter} AND chef_environment:#{env}") do |n|
          nodes << n
        end
      end

      if block_given?
        nodes.each { |n| yield n }
      else
        single ? nodes.first : nodes
      end
    end
Search for a matching node by a given role or tag.

 @param [Symbol] type
   The filter type, can be `:role` or `:tag`.

 @param [String] filter
   The role or tag to filter on.

 @param [Boolean] single
   True if we should return only a single match, or false to return all
   of the matches.

 @yield an optional block to enumerate over the nodes.

 @return [Array, Proc]
   The value of the passed block or node.

 @api public