Class: Templator::Parameters

Inherits:
Object
  • Object
show all
Defined in:
lib/templator/parameters.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.load_files(*paths) ⇒ Parameters

Loads parameter files from given paths.

Parameters:

  • paths (Array<String>)

    list of paths that match parameter files. Each element can match an individual file or a directory, in this case all files included at the root of this directory are assumed to be parameter files.

Returns:

  • (Parameters)

    a Parameters instance. This instance is suitable to provide a later access to parameters defined in loaded files.



19
20
21
22
23
24
25
26
# File 'lib/templator/parameters.rb', line 19

def self.load_files(*paths)

  files = ParameterFileSelector.select_parameter_files(*paths)

  parameters = Parameters.new
  parameters.load(files)
  return parameters
end

Instance Method Details

#get(var) ⇒ Object

Retrieves the value of a variable defined in the parameter files previously loaded.

Parameters:

  • var (#to_s)

    the fully qualified name of the variable (in dot notation)



31
32
33
# File 'lib/templator/parameters.rb', line 31

def get(var)
  var.to_s.split('.').inject(@parameters) {|result, element| result.send(element)} 
end

#load(files) ⇒ Object

Loads parameters from provided files.

Parameters:

  • files (Array<String>)

    files to load.



37
38
39
# File 'lib/templator/parameters.rb', line 37

def load(files)
  @parameters = Templator::ParameterFileLoader.new.parse(*files)
end