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



42
43
44
45
46
# File 'lib/cobra_commander/source.rb', line 42

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

Instance Method Details

#around_command {|env| ... } ⇒ Object

Wraps the execution of commands on this source’s packages, letting the source enhance the surrounding process (e.g. Bundler isolation) and contribute environment variables to the command. The base implementation yields an empty env; plugins override it (see CobraCommander::Ruby::Bundle).

Yield Parameters:

  • env (Hash{String => String})

    env vars to pass to the command

Returns:

  • the value returned by the block



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

def around_command
  yield({})
end

#eachObject



36
37
38
39
40
# File 'lib/cobra_commander/source.rb', line 36

def each(&)
  packages.each(&)
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