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.
51 52 53 |
# File 'lib/kitchen/collection.rb', line 51 def as_names __getobj__.map(&:name) end |
#get(name) ⇒ Object
Returns a single object by its name, or nil if none are found.
34 35 36 |
# File 'lib/kitchen/collection.rb', line 34 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.
44 45 46 |
# File 'lib/kitchen/collection.rb', line 44 def get_all(regexp) Kitchen::Collection.new(__getobj__.select { |i| i.name =~ regexp }) end |