Class: Confswap::PropertyFileVariableReader
- Inherits:
-
Object
- Object
- Confswap::PropertyFileVariableReader
show all
- Defined in:
- lib/confswap/property_reader.rb
Defined Under Namespace
Classes: InvalidPropertyFileException
Class Method Summary
collapse
Class Method Details
29
30
31
|
# File 'lib/confswap/property_reader.rb', line 29
def self. line
line.start_with? '#'
end
|
25
26
27
|
# File 'lib/confswap/property_reader.rb', line 25
def self. file_contents
file_contents.reject{|v| v.empty? || self.(v) }
end
|
.parse_file_contents(contents) ⇒ Object
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/confswap/property_reader.rb', line 8
def self.parse_file_contents contents
raise InvalidPropertyFileException unless self.valid_property_file_contents? contents
raw_file_contents = contents.split(/\n/)
variables = self.(raw_file_contents)
variables_hash = {}
variables.each { |variable_line|
split_variable_line = variable_line.split(/:/, 2)
variable_key = split_variable_line.first.to_sym
variable_value = split_variable_line.at(1).strip
variables_hash[variable_key] = variable_value
}
variables_hash
end
|
.read_variables_from_file(file_path) ⇒ Object
2
3
4
5
|
# File 'lib/confswap/property_reader.rb', line 2
def self.read_variables_from_file file_path
contents = File.read file_path
self.parse_file_contents contents
end
|
.valid_property_file_contents?(property_file_contents) ⇒ Boolean
33
34
35
36
|
# File 'lib/confswap/property_reader.rb', line 33
def self.valid_property_file_contents? property_file_contents
file_contents_not_empty = !property_file_contents.empty?
file_contents_not_empty
end
|