Class: CobraCommander::Source

Inherits:
Object
  • Object
show all
Extended by:
Registry
Includes:
Enumerable
Defined in:
lib/cobra_commander/source.rb

Constant Summary collapse

Error =
Class.new(StandardError)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Registry

[], all, select

Constructor Details

#initialize(path, config) ⇒ Source

Returns a new instance of Source.



15
16
17
18
19
# File 'lib/cobra_commander/source.rb', line 15

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

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



13
14
15
# File 'lib/cobra_commander/source.rb', line 13

def config
  @config
end

#pathObject (readonly)

Returns the value of attribute path.



13
14
15
# File 'lib/cobra_commander/source.rb', line 13

def path
  @path
end

Class Method Details

.load(path, config = nil, **selector) ⇒ Object



31
32
33
34
35
# File 'lib/cobra_commander/source.rb', line 31

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

Instance Method Details

#each(&block) ⇒ Object



25
26
27
28
29
# File 'lib/cobra_commander/source.rb', line 25

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

#to_aryObject



21
22
23
# File 'lib/cobra_commander/source.rb', line 21

def to_ary
  to_a
end