Module: Chef::Mixin::VersionedAPIFactory
- Included in:
- CookbookManifestVersions
- Defined in:
- lib/chef/mixin/versioned_api.rb
Instance Method Summary collapse
- #add_versioned_api_class(klass) ⇒ Object
-
#best_request_version ⇒ Object
When teeing up an HTTP request, we need to be able to ask which API version we should use.
- #def_versioned_delegator(method) ⇒ Object
- #get_class_for(type) ⇒ Object
- #new(*args) ⇒ Object
- #possible_requests ⇒ Object
- #versioned_api_class ⇒ Object
- #versioned_interfaces ⇒ Object
Instance Method Details
#add_versioned_api_class(klass) ⇒ Object
38 39 40 |
# File 'lib/chef/mixin/versioned_api.rb', line 38 def add_versioned_api_class(klass) versioned_interfaces << klass end |
#best_request_version ⇒ Object
When teeing up an HTTP request, we need to be able to ask which API version we should use. Something in Net::HTTP seems to expect to strip headers, so we return this as a string.
67 68 69 70 |
# File 'lib/chef/mixin/versioned_api.rb', line 67 def best_request_version klass = get_class_for(:max_server_version) klass.minimum_api_version.to_s end |
#def_versioned_delegator(method) ⇒ Object
56 57 58 59 60 61 62 63 |
# File 'lib/chef/mixin/versioned_api.rb', line 56 def def_versioned_delegator(method) line_no = __LINE__; str = %{ def self.#{method}(*args, &block) versioned_api_class.__send__(:#{method}, *args, &block) end } module_eval(str, __FILE__, line_no) end |
#get_class_for(type) ⇒ Object
46 47 48 49 50 51 52 53 54 |
# File 'lib/chef/mixin/versioned_api.rb', line 46 def get_class_for(type) versioned_interfaces.select do |klass| version = klass.send(:minimum_api_version) # min and max versions will be nil if we've not made a request to the server yet, # in which case we'll just start with the highest version and see what happens ServerAPIVersions.instance.min_server_version.nil? || (version >= ServerAPIVersions.instance.min_server_version && version <= ServerAPIVersions.instance.send(type)) end .max_by { |a| a.send(:minimum_api_version) } end |
#new(*args) ⇒ Object
76 77 78 79 80 |
# File 'lib/chef/mixin/versioned_api.rb', line 76 def new(*args) object = versioned_api_class.allocate object.send(:initialize, *args) object end |
#possible_requests ⇒ Object
72 73 74 |
# File 'lib/chef/mixin/versioned_api.rb', line 72 def possible_requests versioned_interfaces.length end |
#versioned_api_class ⇒ Object
42 43 44 |
# File 'lib/chef/mixin/versioned_api.rb', line 42 def versioned_api_class get_class_for(:max_server_version) end |
#versioned_interfaces ⇒ Object
34 35 36 |
# File 'lib/chef/mixin/versioned_api.rb', line 34 def versioned_interfaces @versioned_interfaces ||= [] end |