Sha256: de495ef0dc95f128a691a16588b22ba0e04db92c47537bf6666fd4e9c2ae51fa

Contents?: true

Size: 1.02 KB

Versions: 18

Compression:

Stored size: 1.02 KB

Contents

module Berkshelf
  class Lockfile
    class << self
      def remove!
        FileUtils.rm_f DEFAULT_FILENAME
      end
    end

    DEFAULT_FILENAME = "#{Berkshelf::DEFAULT_FILENAME}.lock".freeze

    attr_reader :sources

    def initialize(sources)
      @sources = Array(sources)
    end

    def write(filename = DEFAULT_FILENAME)
      content = sources.map { |source| get_source_definition(source) }.join("\n")
      File.open(filename, "wb") { |f| f.write content }
    end

    def remove!
      self.class.remove!
    end

    private

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

        if source.location.is_a?(GitLocation)
          definition += ", :git => '#{source.location.uri}', :ref => '#{source.location.branch || 'HEAD'}'"
        elsif source.location.is_a?(PathLocation)
          definition += ", :path => '#{source.location.path}'"
        else
          definition += ", :locked_version => '#{source.locked_version}'"
        end

        return definition
      end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
berkshelf-1.0.4 lib/berkshelf/lockfile.rb
berkshelf-1.0.3 lib/berkshelf/lockfile.rb
berkshelf-1.0.2 lib/berkshelf/lockfile.rb
berkshelf-1.0.0 lib/berkshelf/lockfile.rb
berkshelf-1.0.0.rc3 lib/berkshelf/lockfile.rb
berkshelf-1.0.0.rc2 lib/berkshelf/lockfile.rb
berkshelf-1.0.0.rc1 lib/berkshelf/lockfile.rb
berkshelf-0.6.0.beta4 lib/berkshelf/lockfile.rb
berkshelf-0.6.0.beta3 lib/berkshelf/lockfile.rb
berkshelf-0.6.0.beta2 lib/berkshelf/lockfile.rb
berkshelf-0.5.1 lib/berkshelf/lockfile.rb
berkshelf-0.6.0.beta1 lib/berkshelf/lockfile.rb
berkshelf-0.5.0 lib/berkshelf/lockfile.rb
berkshelf-0.5.0.rc4 lib/berkshelf/lockfile.rb
berkshelf-0.5.0.rc3 lib/berkshelf/lockfile.rb
berkshelf-0.5.0.rc2 lib/berkshelf/lockfile.rb
berkshelf-0.5.0.rc1 lib/berkshelf/lockfile.rb
berkshelf-0.4.0 lib/berkshelf/lockfile.rb