Class: TBM::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/TBM/config.rb

Overview

Configuration for the Tunnel Boring Machine. This class is both the parser of the configuration data in YAML form, and the artifact that results from the parsing.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



13
14
15
16
# File 'lib/TBM/config.rb', line 13

def initialize
	@errors = []
	@targets = []
end

Instance Attribute Details

#errorsObject (readonly)

Any errors discovered while parsing the configuration.



8
9
10
# File 'lib/TBM/config.rb', line 8

def errors
  @errors
end

#targetsObject (readonly)

The targets defined in the configuration.



11
12
13
# File 'lib/TBM/config.rb', line 11

def targets
  @targets
end

Instance Method Details

#each_target {|target| ... } ⇒ Object

Iterate over each target and yield to the specified block.

Yields:

  • (target)

    a block to which each target will be passed



35
36
37
# File 'lib/TBM/config.rb', line 35

def each_target( &block )
	@targets.each { |target| yield target }
end

#get_target(name) ⇒ Object

Request a target having the specified name.

Parameters:

  • name (String)

    the name of the target



28
29
30
# File 'lib/TBM/config.rb', line 28

def get_target( name )
	@targets.find { |target| target.has_name?(name) }
end

#valid?Boolean

The configuration is valid if there are no errors.

Returns:

  • (Boolean)

    true if the error collection is empty



21
22
23
# File 'lib/TBM/config.rb', line 21

def valid?
	@errors.empty?
end