Sha256: 3d32bf9b83497f17d50d1d5419631c0af2960a0603226312412b36b7985ae0b2

Contents?: true

Size: 707 Bytes

Versions: 3

Compression:

Stored size: 707 Bytes

Contents

# frozen_string_literal: true

require "cobra_commander/package"
require "cobra_commander/registry"

module CobraCommander
  class Source
    Error = Class.new(StandardError)

    include Enumerable
    extend CobraCommander::Registry

    attr_reader :path, :config

    def initialize(path, config)
      @path = Pathname.new(path)
      @config = config || {}
      super()
    end

    def to_ary
      to_a
    end

    def each(&block)
      packages.each(&block)
    rescue Errno::ENOENT => e
      raise Error, e.message
    end

    def self.load(path, config = nil, **selector)
      select(**selector).map do |source|
        source.new(path, config&.dig(source.key))
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
cobra_commander-1.1.0 lib/cobra_commander/source.rb
cobra_commander-1.0.1 lib/cobra_commander/source.rb
cobra_commander-1.0.0 lib/cobra_commander/source.rb