class ChefDK::Policyfile::ReadCookbookForCompatModeUpload

TODO: when compat mode is removed, this class should be removed and the file should be renamed

Attributes

cookbook_name[R]
directory_path[R]
version_override[R]

Public Class Methods

load(name, version_override, directory_path) click to toggle source

Convenience method to load a cookbook, set up name and version overrides as necessary, and return a Chef::CookbookVersion object.

# File lib/chef-dk/policyfile/read_cookbook_for_compat_mode_upload.rb, line 71
def self.load(name, version_override, directory_path)
  new(name, version_override, directory_path).cookbook_version
end
new(cookbook_name, version_override, directory_path) click to toggle source
# File lib/chef-dk/policyfile/read_cookbook_for_compat_mode_upload.rb, line 79
def initialize(cookbook_name, version_override, directory_path)
  @cookbook_name = cookbook_name
  @version_override = version_override
  @directory_path = directory_path

  @cookbook_version = nil
  @loader = nil
end

Public Instance Methods

chefignore() click to toggle source
# File lib/chef-dk/policyfile/read_cookbook_for_compat_mode_upload.rb, line 118
def chefignore
  @chefignore ||= Chef::Cookbook::Chefignore.new(File.join(directory_path, "chefignore"))
end
cookbook_version() click to toggle source
# File lib/chef-dk/policyfile/read_cookbook_for_compat_mode_upload.rb, line 88
def cookbook_version
  @cookbook_version ||=
    begin
      cookbook_version = loader.cookbook_version
      # TODO: dont do this for non-compat mode
      cookbook_version.version = version_override
      # TODO: dont do this either

      # Fixup manifest.
      # What happens is, the 'manifest' representation of cookbook
      # version is created, it has a "name" field like foo-1.0.0, then we
      # change the version to 1234.5678.9876 but the manifest is not
      # regenerated so erchef rejects our upload b/c the name field
      # doesn't match the expected `$cookbook_name-$version` based on the
      # other fields.
      cookbook_version.manifest[:name] = "#{cookbook_version.name}-#{version_override}"
      cookbook_version.freeze_version
      cookbook_version
    end
end
loader() click to toggle source
# File lib/chef-dk/policyfile/read_cookbook_for_compat_mode_upload.rb, line 109
def loader
  @loader ||=
    begin
      cbvl = Chef::Cookbook::CookbookVersionLoader.new(directory_path, chefignore)
      cbvl.load!
      cbvl
    end
end