class ChefCLI::Policyfile::CookbookLock

Base class for CookbookLock implementations

def assert_required_keys_valid!(lock_data)

def assert_required_keys_valid!(lock_data)
  missing_keys = REQUIRED_LOCK_DATA_KEYS.reject { |key| lock_data.key?(key) }
  unless missing_keys.empty?
    raise InvalidLockfile, "Lockfile cookbook_lock for #{name} missing required attributes `#{missing_keys.join("', `")}'"
  end
  version = lock_data["version"]
  unless version.is_a?(String)
    raise InvalidLockfile, "Lockfile cookbook_lock for #{name} `version' attribute must be a string (got: #{version})"
  end
  identifier = lock_data["identifier"]
  unless identifier.is_a?(String)
    raise InvalidLockfile, "Lockfile cookbook_lock for #{name} `identifier' attribute must be a string (got: #{identifier})"
  end
  cache_key = lock_data["cache_key"]
  unless cache_key.is_a?(String) || cache_key.nil?
    raise InvalidLockfile, "Lockfile cookbook_lock for #{name} `cache_key' attribute must be a string (got: #{cache_key})"
  end
  source_options = lock_data["source_options"]
  unless source_options.is_a?(Hash)
    raise InvalidLockfile, "Lockfile cookbook_lock for #{name} `source_options' attribute must be a Hash (JSON object) (got: #{source_options})"
  end
end

def build_from_lock_data(lock_data)

def build_from_lock_data(lock_data)
  raise NotImplementedError, "#{self.class} must override #build_from_lock_data with a specific implementation"
end

def chefignore

def chefignore
  @chefignore ||= Chef::Cookbook::Chefignore.new(File.join(cookbook_path, "chefignore"))
end

def cookbook_loader

def cookbook_loader
  @cookbook_loader ||=
    begin
      loader = Chef::Cookbook::CookbookVersionLoader.new(cookbook_path, chefignore)
      loader.load!
      loader
    end
end

def cookbook_location_spec

def cookbook_location_spec
  raise InvalidCookbookLockData, "Cannot create CookbookLocationSpecification for #{name} without version" if version.nil?
  raise InvalidCookbookLockData, "Cannot create CookbookLocationSpecification for #{name} without source options" if source_options.nil?
  @location_spec ||= CookbookLocationSpecification.new(name, "= #{version}", source_options, storage_config)
end

def cookbook_path

def cookbook_path
  raise NotImplementedError, "#{self.class} must override #cookbook_path with a specific implementation"
end

def cookbook_version

def cookbook_version
  @cookbook_version ||= cookbook_loader.cookbook_version
end

def dependencies

def dependencies
  cookbook_location_spec.dependencies
end

def gather_profile_data

def gather_profile_data
  @identifier ||= identifiers.content_identifier
  @dotted_decimal_identifier ||= identifiers.dotted_decimal_identifier
  @version ||= identifiers.semver_version
end

def identifier_updated?

def identifier_updated?
  false
end

def identifiers

def identifiers
  @identifiers ||= CookbookProfiler::Identifiers.new(cookbook_version)
end

def initialize(name, storage_config)

def initialize(name, storage_config)
  @name = name
  @version = nil
  @source_options = nil
  @identifier = nil
  @dotted_decimal_identifier = nil
  @storage_config = storage_config
end

def install_locked

def install_locked
  cookbook_location_spec.ensure_cached
end

def installed?

def installed?
  cookbook_location_spec.installed?
end

def lock_data

def lock_data
  raise NotImplementedError, "#{self.class} must override #lock_data a specific implementation"
end

def refresh!

def refresh!
  raise NotImplementedError, "#{self.class} must override #refresh! with a specific implementation"
end

def symbolize_source_options_keys(source_options_from_json)

def symbolize_source_options_keys(source_options_from_json)
  source_options_from_json ||= {}
  source_options_from_json.inject({}) do |normalized_source_opts, (key, value)|
    normalized_source_opts[key.to_sym] = value
    normalized_source_opts
  end
end

def to_lock

def to_lock
  validate!
  lock_data
end

def updated?

def updated?
  false
end

def validate!

def validate!
  raise NotImplementedError, "#{self.class} must override #validate! with a specific implementation"
end

def version_updated?

def version_updated?
  false
end