Sha256: d0c156022324c88e25e86eb0dcfdcc0ee655df4e9429f65e94fed3bb0d1bf39a

Contents?: true

Size: 1.67 KB

Versions: 23

Compression:

Stored size: 1.67 KB

Contents

# frozen_string_literal: true

require_relative 'changelog'

class KnifeChangelog
  class Changelog
    class Berksfile < Changelog
      def initialize(berksfile, config)
        require 'berkshelf'
        @locked_versions = berksfile.lockfile.locks
        @sources = berksfile.sources
        @berksfile = berksfile
        super(config)
      end

      def all_cookbooks
        @locked_versions.keys
      end

      def new_cookbook?(name)
        ck_dep(name).nil?
      end

      # return true if cookbook is downloaded from supermarket
      def supermarket?(name)
        # here is berkshelf "expressive" way to say cookbook
        # comes from supermarket
        ck_dep(name).location.is_a?(NilClass)
      end

      # return true if cookbook is downloaded from git
      def git?(name)
        ck_dep(name).location.is_a?(Berkshelf::GitLocation)
      end

      # return true if cookbook is downloaded from local path
      def local?(name)
        ck_dep(name).location.is_a?(Berkshelf::PathLocation)
      end

      # return a Changelog::Location for this cookbook
      def git_location(name)
        raise "#{name} has not a git location" unless git?(name)
        Location.from_berk_git_location(ck_dep(name).location)
      end

      # return a list of supermarket uri for a given cookbook
      # example: [ 'https://supermarket.chef.io' ]
      def supermarkets_for(_name)
        @sources.map(&:uri)
      end

      def guess_version_for(name)
        @locked_versions[name].locked_version.to_s
      end

      def update(cookbooks)
        @berksfile.update(*cookbooks)
      end

      private

      def ck_dep(name)
        @locked_versions[name]
      end
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
knife-changelog-2.0.0 lib/knife/changelog/berksfile.rb
knife-changelog-1.7.0 lib/knife/changelog/berksfile.rb
knife-changelog-1.6.0 lib/knife/changelog/berksfile.rb
knife-changelog-1.5.0 lib/knife/changelog/berksfile.rb
knife-changelog-1.4.2 lib/knife/changelog/berksfile.rb
knife-changelog-1.4.1 lib/knife/changelog/berksfile.rb
knife-changelog-1.4.0 lib/knife/changelog/berksfile.rb
knife-changelog-1.3.0 lib/knife/changelog/berksfile.rb
knife-changelog-1.2.5 lib/knife/changelog/berksfile.rb
knife-changelog-1.2.4 lib/knife/changelog/berksfile.rb
knife-changelog-1.2.3 lib/knife/changelog/berksfile.rb
knife-changelog-1.2.2 lib/knife/changelog/berksfile.rb
knife-changelog-1.2.1 lib/knife/changelog/berksfile.rb
knife-changelog-1.2.0 lib/knife/changelog/berksfile.rb
knife-changelog-1.1.0 lib/knife/changelog/berksfile.rb
knife-changelog-1.0.10 lib/knife/changelog/berksfile.rb
knife-changelog-1.0.9 lib/knife/changelog/berksfile.rb
knife-changelog-1.0.8 lib/knife/changelog/berksfile.rb
knife-changelog-1.0.7 lib/knife/changelog/berksfile.rb
knife-changelog-1.0.6 lib/knife/changelog/berksfile.rb