Sha256: 61c61d08498dd07a882bbf3887c4cf750136d7243e983681c620c5c163461a6d

Contents?: true

Size: 1.11 KB

Versions: 4

Compression:

Stored size: 1.11 KB

Contents

module Berkshelf
  class Source
    include Comparable

    # @return [Berkshelf::SourceURI]
    attr_reader :uri

    # @param [String, Berkshelf::SourceURI] uri
    def initialize(uri)
      @uri        = SourceURI.parse(uri)
      @api_client = APIClient.new(uri)
    end

    # @return [Hash]
    def universe
      @universe ||= api_client.universe
    end

    # @param [String] name
    # @param [String] version
    #
    # @return [APIClient::RemoteCookbook]
    def cookbook(name, version)
      universe.find { |cookbook| cookbook.name == name && cookbook.version == version }
    end

    # @param [String] name
    #
    # @return [APIClient::RemoteCookbook]
    def latest(name)
      versions(name).sort.last
    end

    # @param [String] name
    #
    # @return [Array<APIClient::RemoteCookbook>]
    def versions(name)
      universe.select { |cookbook| cookbook.name == name }
    end

    def to_s
      uri.to_s
    end

    def ==(other)
      return false unless other.is_a?(self.class)
      uri == other.uri
    end

    private

      # @return [Berkshelf::APIClient]
      attr_reader :api_client
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
berkshelf-3.0.0.beta4 lib/berkshelf/source.rb
berkshelf-3.0.0.beta3 lib/berkshelf/source.rb
berkshelf-3.0.0.beta2 lib/berkshelf/source.rb
berkshelf-3.0.0.beta1 lib/berkshelf/source.rb