class ChefCLI::Policyfile::LocalCookbook
filesystem and are assumed to be under active development.
LocalCookbook objects represent cookbooks that are sourced from the local
def assert_required_keys_valid!(lock_data)
def assert_required_keys_valid!(lock_data) super source = lock_data["source"] if source.nil? raise InvalidLockfile, "Lockfile cookbook_lock for #{name} is invalid. Lock data for a local cookbook must have a `source' attribute" end unless source.is_a?(String) raise InvalidLockfile, "Lockfile cookbook_lock for #{name} is invalid: `source' attribute must be a String (got: #{source.inspect})" end end
def build_from_lock_data(lock_data)
def build_from_lock_data(lock_data) assert_required_keys_valid!(lock_data) @version = lock_data["version"] @identifier = lock_data["identifier"] @dotted_decimal_identifier = lock_data["dotted_decimal_identifier"] @source = lock_data["source"] @source_options = symbolize_source_options_keys(lock_data["source_options"]) @scm_info = lock_data["scm_info"] end
def cookbook_in_git_repo?
def cookbook_in_git_repo? return @cookbook_in_git_repo unless @cookbook_in_git_repo.nil? @cookbook_in_git_repo = false dot_git = Pathname.new(".git") Pathname.new(cookbook_path).ascend do |parent_dir| possible_git_dir = parent_dir + dot_git if possible_git_dir.exist? @cookbook_in_git_repo = true break end end @cookbook_in_git_repo end
def cookbook_path
def cookbook_path File.expand_path(source, relative_paths_root) end
def identifier_updated?
def identifier_updated? @identifier_updated end
def initialize(name, storage_config)
def initialize(name, storage_config) @name = name @identifier = nil @storage_config = storage_config @identifier_updated = false @version_updated = false @cookbook_in_git_repo = nil @scm_info = nil end
def lock_data
def lock_data { "version" => version, "identifier" => identifier, "dotted_decimal_identifier" => dotted_decimal_identifier, "source" => source, "cache_key" => nil, "scm_info" => scm_info, "source_options" => source_options, } end
def refresh!
def refresh! old_identifier, old_version = @identifier, @version @identifier, @dotted_decimal_identifier, @version = nil, nil, nil gather_profile_data if @identifier != old_identifier @identifier_updated = true end if @version != old_version @version_updated = true end self end
def refresh_scm_info
def refresh_scm_info @scm_info = scm_profiler.profile_data end
def scm_info
def scm_info @scm_info end
def scm_profiler
def scm_profiler if cookbook_in_git_repo? CookbookProfiler::Git.new(cookbook_path) else CookbookProfiler::NullSCM.new(cookbook_path) end end
def to_lock
def to_lock refresh_scm_info super end
def updated?
def updated? @identifier_updated || @version_updated end
def validate!
def validate! if source.nil? raise LocalCookbookNotFound, "Cookbook `#{name}' does not have a `source` set, cannot locate cookbook" end unless File.exist?(cookbook_path) raise LocalCookbookNotFound, "Cookbook `#{name}' not found at path source `#{source}` (full path: `#{cookbook_path}')" end unless cookbook_version.name.to_s == name msg = "The cookbook at path source `#{source}' is expected to be named `#{name}', but is now named `#{cookbook_version.name}' (full path: #{cookbook_path})" raise MalformedCookbook, msg end end
def version_updated?
def version_updated? @version_updated end