Module: Siba::OptionsLoader
- Extended by:
- LoggerPlug
- Defined in:
- lib/siba/options_loader.rb
Class Method Summary
collapse
Methods included from LoggerPlug
close, create, logger, logger, opened?
Class Method Details
.load_erb(path_to_file) ⇒ Object
32
33
34
35
|
# File 'lib/siba/options_loader.rb', line 32
def load_erb(path_to_file)
data = Siba::FileHelper.read path_to_file
ERB.new(data).result
end
|
.load_hash_from_yml(path_to_yml) ⇒ Object
28
29
30
|
# File 'lib/siba/options_loader.rb', line 28
def load_hash_from_yml(path_to_yml)
YAML.load(load_erb path_to_yml)
end
|
.load_yml(path_to_yml) ⇒ Object
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/siba/options_loader.rb', line 10
def load_yml(path_to_yml)
logger.debug "Loading options from #{path_to_yml}"
raise Siba::Error, "Options file must have .yml extension: #{path_to_yml}" unless path_to_yml =~ /\.yml$/
unless File.exists? path_to_yml
raise Siba::Error, "Could not read the options file #{path_to_yml}.
Make sure the file exists and you have read access to it."
end
begin
hash = load_hash_from_yml path_to_yml
raise Siba::Error, "invalid format" unless hash.is_a? Hash
return hash
rescue Exception => e
raise Siba::Error, "Error loading options file #{path_to_yml}: " + e.message
end
end
|