Sha256: f834798101baa62a30267f108f2795aecfa47208b8fcd23bfdf1e9266d628136

Contents?: true

Size: 1011 Bytes

Versions: 5

Compression:

Stored size: 1011 Bytes

Contents

module KnifeCookbookDependencies
  class Lockfile
    DEFAULT_FILENAME = "#{KCD::DEFAULT_FILENAME}.lock"

    def initialize(cookbooks)
      @cookbooks = cookbooks
    end

    def write(filename = DEFAULT_FILENAME)
      content = @cookbooks.map do |cookbook|
                  get_cookbook_definition(cookbook)
                end.join("\n")
      File.open(DEFAULT_FILENAME, "wb") { |f| f.write content }
    end

    def get_cookbook_definition(cookbook)
      definition = "cookbook '#{cookbook.name}'"

      if cookbook.from_git?
        definition += ", :git => '#{cookbook.git_repo}', :ref => '#{cookbook.git_ref || 'HEAD'}'"
      elsif cookbook.from_path?
        definition += ", :path => '#{cookbook.local_path}'"
      else
        definition += ", :locked_version => '#{cookbook.locked_version}'"
      end

      return definition
    end

    def remove!
      self.class.remove!
    end

    class << self
      def remove!
        FileUtils.rm_f DEFAULT_FILENAME
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
knife_cookbook_dependencies_over_http-0.0.8.3 lib/kcd/lockfile.rb
knife_cookbook_dependencies_over_http-0.0.8.2 lib/kcd/lockfile.rb
knife_cookbook_dependencies_over_http-0.0.8.1 lib/kcd/lockfile.rb
knife_cookbook_dependencies_over_http-0.0.8 lib/kcd/lockfile.rb
knife_cookbook_dependencies-0.0.8 lib/kcd/lockfile.rb