class Kitchen::Collection

Delegate class which adds the ability to find single and multiple objects by their name in an Array. Hey, it's better than monkey-patching Array, right?

@author Fletcher Nichol <fnichol@nichol.ca>

Public Instance Methods

as_names() click to toggle source

Returns an Array of names from the collection as strings.

@return [Array<String>] array of name strings

# File lib/kitchen/collection.rb, line 48
def as_names
  __getobj__.map(&:name)
end
get(name) click to toggle source

Returns a single object by its name, or nil if none are found.

@param name [String] name of object @return [Object] first match by name, or nil if none are found

# File lib/kitchen/collection.rb, line 31
def get(name)
  __getobj__.find { |i| i.name == name }
end
get_all(regexp) click to toggle source

Returns a Collection of all objects whose name is matched by the regular expression.

@param regexp [Regexp] a regular expression pattern @return [Kitchen::Config::Collection<Object>] a new collection of

matched objects
# File lib/kitchen/collection.rb, line 41
def get_all(regexp)
  Kitchen::Collection.new(__getobj__.select { |i| i.name =~ regexp })
end