Class: Rancher::Collection
- Includes:
- Enumerable
- Defined in:
- lib/rancher/collection.rb
Overview
A Collection of Resources
Instance Attribute Summary
Attributes inherited from Resource
Instance Method Summary collapse
- #create(attrs) ⇒ Object
- #each ⇒ Object
-
#initialize(data) ⇒ Collection
constructor
A new instance of Collection.
- #remove!(id_or_obj) ⇒ Object
Methods inherited from Resource
#action, #action?, #get_link, #in_meta?, #method_missing, #save!
Constructor Details
#initialize(data) ⇒ Collection
Returns a new instance of Collection.
7 8 9 10 |
# File 'lib/rancher/collection.rb', line 7 def initialize(data) @data = data[:data] if data.key?(:data) super(data) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Rancher::Resource
Instance Method Details
#create(attrs) ⇒ Object
12 13 14 15 16 |
# File 'lib/rancher/collection.rb', line 12 def create(attrs) attrs = attrs. if attrs.is_a?(Rancher::Resource) Rancher.post get_link('self'), attrs end |
#each ⇒ Object
25 26 27 28 29 |
# File 'lib/rancher/collection.rb', line 25 def each return @data.enum_for(:each) unless block_given? @data.each { |d| yield d } end |