Sha256: 5a889b57ed5e2b668b7b4c6ee4862d21d2290c3e61949ba7e57d69d6353c79ee

Contents?: true

Size: 1.06 KB

Versions: 15

Compression:

Stored size: 1.06 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?(CookbookSource::GitLocation)
          definition += ", :git => '#{source.location.uri}', :ref => '#{source.location.branch || 'HEAD'}'"
        elsif source.location.is_a?(CookbookSource::PathLocation)
          definition += ", :path => '#{source.location.path}'"
        else
          definition += ", :locked_version => '#{source.locked_version}'"
        end

        return definition
      end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
berkshelf-0.4.0.rc4 lib/berkshelf/lockfile.rb
berkshelf-0.4.0.rc3 lib/berkshelf/lockfile.rb
berkshelf-0.4.0.rc2 lib/berkshelf/lockfile.rb
berkshelf-0.4.0.rc1 lib/berkshelf/lockfile.rb
berkshelf-0.3.7 lib/berkshelf/lockfile.rb
berkshelf-0.3.3 lib/berkshelf/lockfile.rb
berkshelf-0.3.2 lib/berkshelf/lockfile.rb
berkshelf-0.3.1 lib/berkshelf/lockfile.rb
berkshelf-0.3.0 lib/berkshelf/lockfile.rb
berkshelf-0.2.0 lib/berkshelf/lockfile.rb
berkshelf-0.1.5 lib/berkshelf/lockfile.rb
berkshelf-0.1.4 lib/berkshelf/lockfile.rb
berkshelf-0.1.3 lib/berkshelf/lockfile.rb
berkshelf-0.1.2 lib/berkshelf/lockfile.rb
berkshelf-0.1.1 lib/berkshelf/lockfile.rb