module Chef::Mixin::VersionedAPIFactory

Public Instance Methods

add_versioned_api_class(klass) click to toggle source
# File lib/chef/mixin/versioned_api.rb, line 38
def add_versioned_api_class(klass)
  versioned_interfaces << klass
end
best_request_version() click to toggle source

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.

# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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() click to toggle source
# File lib/chef/mixin/versioned_api.rb, line 72
def possible_requests
  versioned_interfaces.length
end
versioned_api_class() click to toggle source
# File lib/chef/mixin/versioned_api.rb, line 42
def versioned_api_class
  get_class_for(:max_server_version)
end
versioned_interfaces() click to toggle source
# File lib/chef/mixin/versioned_api.rb, line 34
def versioned_interfaces
  @versioned_interfaces ||= []
end