Class: AnsibleTowerClient::Collection
- Inherits:
-
Object
- Object
- AnsibleTowerClient::Collection
- Defined in:
- lib/ansible_tower_client/collection.rb
Instance Attribute Summary collapse
-
#api ⇒ Object
readonly
Returns the value of attribute api.
-
#klass ⇒ Object
readonly
Returns the value of attribute klass.
Instance Method Summary collapse
- #all(get_options = nil) ⇒ Object
- #create(*args) ⇒ Object
- #create!(*args) ⇒ Object
- #find(id) ⇒ Object
- #find_all_by_url(url, get_options = nil) ⇒ Object
-
#initialize(api, klass = nil) ⇒ Collection
constructor
A new instance of Collection.
Constructor Details
#initialize(api, klass = nil) ⇒ Collection
Returns a new instance of Collection.
4 5 6 7 |
# File 'lib/ansible_tower_client/collection.rb', line 4 def initialize(api, klass = nil) @api = api @klass = klass end |
Instance Attribute Details
#api ⇒ Object (readonly)
Returns the value of attribute api.
3 4 5 |
# File 'lib/ansible_tower_client/collection.rb', line 3 def api @api end |
#klass ⇒ Object (readonly)
Returns the value of attribute klass.
3 4 5 |
# File 'lib/ansible_tower_client/collection.rb', line 3 def klass @klass end |
Instance Method Details
#all(get_options = nil) ⇒ Object
11 12 13 |
# File 'lib/ansible_tower_client/collection.rb', line 11 def all( = nil) find_all_by_url("#{klass.endpoint}/", ) end |
#create(*args) ⇒ Object
38 39 40 |
# File 'lib/ansible_tower_client/collection.rb', line 38 def create(*args) klass.create(api, *args) end |
#create!(*args) ⇒ Object
34 35 36 |
# File 'lib/ansible_tower_client/collection.rb', line 34 def create!(*args) klass.create!(api, *args) end |
#find(id) ⇒ Object
30 31 32 |
# File 'lib/ansible_tower_client/collection.rb', line 30 def find(id) build_object(parse_response(api.get(find_uri(id)))) end |
#find_all_by_url(url, get_options = nil) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/ansible_tower_client/collection.rb', line 15 def find_all_by_url(url, = nil) Enumerator.new do |yielder| @collection = [] next_page = url = loop do next_page = fetch_more_results(next_page, ) if @collection.empty? = nil raise StopIteration if @collection.empty? yielder.yield(@collection.shift) end end end |