Sha256: 5f69b1b33066b5dc12f9e793d94add8f167e9ad1b4c48bda7d88c97feb9c4d06

Contents?: true

Size: 1.56 KB

Versions: 4

Compression:

Stored size: 1.56 KB

Contents

require_relative "base"
require_relative "metadata_based_installer"

module CookbookOmnifetch
  class ChefServerLocation < BaseLocation

    attr_reader :cookbook_version
    attr_reader :uri

    def initialize(dependency, options = {})
      super
      @cookbook_version = options[:version]
      @http_client = options[:http_client] || default_chef_server_http_client
      @uri ||= options[:chef_server]
    end

    def cookbook_name
      dependency.name
    end

    def url_path
      "/cookbooks/#{cookbook_name}/#{cookbook_version}"
    end

    def installer
      MetadataBasedInstaller.new(http_client: http_client, url_path: url_path, install_path: install_path)
    end

    def install
      installer.install
    end

    # Determine if this revision is installed.
    #
    # @return [Boolean]
    def installed?
      install_path.exist?
    end

    def http_client
      @http_client
    end

    # The path where this cookbook would live in the store, if it were
    # installed.
    #
    # @return [Pathname, nil]
    def install_path
      @install_path ||= CookbookOmnifetch.storage_path.join(cache_key)
    end

    def lock_data
      { "chef_server" => uri, "version" => cookbook_version }
    end

    def cache_key
      "#{dependency.name}-#{cookbook_version}"
    end

    # @see BaseLocation#cached_cookbook
    def cached_cookbook
      @cached_cookbook ||= CookbookOmnifetch.cached_cookbook_class.from_path(install_path)
    end

    private

    def default_chef_server_http_client
      CookbookOmnifetch.default_chef_server_http_client
    end

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
cookbook-omnifetch-0.12.2 lib/cookbook-omnifetch/chef_server.rb
cookbook-omnifetch-0.10.1 lib/cookbook-omnifetch/chef_server.rb
cookbook-omnifetch-0.10.0 lib/cookbook-omnifetch/chef_server.rb
cookbook-omnifetch-0.9.1 lib/cookbook-omnifetch/chef_server.rb