Class: ChefDK::ChefServerAPIMulti
- Inherits:
-
Object
- Object
- ChefDK::ChefServerAPIMulti
- Defined in:
- lib/chef-dk/chef_server_api_multi.rb
Overview
A wrapper for ‘Chef::ServerAPI` that supports multi-threading by creating a `Chef::ServerAPI` object per-thread.
This is intended to be used for downloading cookbooks from the Chef Infa Server, where the API of the Chef Infra Server requires each file to be downloaded individually.
It also configures ‘Chef::ServerAPI` to enable keepalives by default. To disable them, `keepalives: false` must be set in the options to the constructor.
Constant Summary collapse
- KEEPALIVES_TRUE =
{ keepalives: true }.freeze
Instance Attribute Summary collapse
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
- #client_for_thread ⇒ Object
- #delete(*args) ⇒ Object
- #get(*args) ⇒ Object
- #head(*args) ⇒ Object
-
#initialize(url, opts) ⇒ ChefServerAPIMulti
constructor
A new instance of ChefServerAPIMulti.
- #post(*args) ⇒ Object
- #put(*args) ⇒ Object
- #streaming_request(*args, &block) ⇒ Object
Constructor Details
#initialize(url, opts) ⇒ ChefServerAPIMulti
Returns a new instance of ChefServerAPIMulti.
39 40 41 42 |
# File 'lib/chef-dk/chef_server_api_multi.rb', line 39 def initialize(url, opts) @url = url @opts = KEEPALIVES_TRUE.merge(opts) end |
Instance Attribute Details
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
37 38 39 |
# File 'lib/chef-dk/chef_server_api_multi.rb', line 37 def opts @opts end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
36 37 38 |
# File 'lib/chef-dk/chef_server_api_multi.rb', line 36 def url @url end |
Instance Method Details
#client_for_thread ⇒ Object
68 69 70 |
# File 'lib/chef-dk/chef_server_api_multi.rb', line 68 def client_for_thread Thread.current[:chef_server_api_multi] ||= Chef::ServerAPI.new(@url, @opts) end |
#delete(*args) ⇒ Object
60 61 62 |
# File 'lib/chef-dk/chef_server_api_multi.rb', line 60 def delete(*args) client_for_thread.delete(*args) end |
#get(*args) ⇒ Object
48 49 50 |
# File 'lib/chef-dk/chef_server_api_multi.rb', line 48 def get(*args) client_for_thread.get(*args) end |
#head(*args) ⇒ Object
44 45 46 |
# File 'lib/chef-dk/chef_server_api_multi.rb', line 44 def head(*args) client_for_thread.head(*args) end |
#post(*args) ⇒ Object
56 57 58 |
# File 'lib/chef-dk/chef_server_api_multi.rb', line 56 def post(*args) client_for_thread.post(*args) end |
#put(*args) ⇒ Object
52 53 54 |
# File 'lib/chef-dk/chef_server_api_multi.rb', line 52 def put(*args) client_for_thread.put(*args) end |
#streaming_request(*args, &block) ⇒ Object
64 65 66 |
# File 'lib/chef-dk/chef_server_api_multi.rb', line 64 def streaming_request(*args, &block) client_for_thread.streaming_request(*args, &block) end |