Class: Externals::YamlConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/externals/yaml_config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base_dir, config_path) ⇒ YamlConfig

Returns a new instance of YamlConfig.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/externals/yaml_config.rb', line 8

def initialize(base_dir, config_path)
  @base_dir = base_dir
  if config_path && File.exists?(config_path)
    config = YAML.load(File.read(config_path))
    @repositories = config.map do |name, attributes|
      Repository.new(@base_dir, name, attributes["repo"], attributes["path"])
    end
    @repositories = @repositories.sort do |a, b|
      a.name <=> b.name
    end
  else
    $stderr.puts "config/externals.yml is missing"
    @repositories = []
  end
end

Instance Attribute Details

#repositoriesObject (readonly)

Returns the value of attribute repositories.



6
7
8
# File 'lib/externals/yaml_config.rb', line 6

def repositories
  @repositories
end

Instance Method Details

#each_repo(filter = nil) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/externals/yaml_config.rb', line 24

def each_repo(filter = nil)
  repositories.each do |r|
    if block_given? and (!filter or filter.match(r.name))
      yield(r)
    end
  end
end