Class: Kitchen::Collection
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- Kitchen::Collection
- Defined in:
- lib/kitchen/collection.rb
Overview
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?
Instance Method Summary collapse
-
#as_names ⇒ Array<String>
Returns an Array of names from the collection as strings.
-
#get(name) ⇒ Object
Returns a single object by its name, or nil if none are found.
-
#get_all(regexp) ⇒ Kitchen::Config::Collection<Object>
Returns a Collection of all objects whose #name is matched by the regular expression.
Instance Method Details
#as_names ⇒ Array<String>
Returns an Array of names from the collection as strings.
48 49 50 |
# File 'lib/kitchen/collection.rb', line 48 def as_names __getobj__.map(&:name) end |
#get(name) ⇒ Object
Returns a single object by its name, or nil if none are found.
31 32 33 |
# File 'lib/kitchen/collection.rb', line 31 def get(name) __getobj__.find { |i| i.name == name } end |
#get_all(regexp) ⇒ Kitchen::Config::Collection<Object>
Returns a Collection of all objects whose #name is matched by the regular expression.
41 42 43 |
# File 'lib/kitchen/collection.rb', line 41 def get_all(regexp) Kitchen::Collection.new(__getobj__.select { |i| i.name =~ regexp }) end |