Module: ServantConfigHelper

Defined in:
lib/belphanior/servant/servant_config.rb

Constant Summary collapse

DEFAULT_CONFIG_PATH =
"servant_config"

Class Method Summary collapse

Class Method Details

.prepare_config_file(file_path, config) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/belphanior/servant/servant_config.rb', line 7

def self.prepare_config_file(file_path, config)
  if File.exist? file_path
    config_file = File.open(file_path, 'r')
    new_config = ServantConfigDb.new(config_file.read)
    config_file.close
    return new_config
  else
    write_config_file(file_path, config)
    return config
  end
end

.write_config_file(file_path, config) ⇒ Object

Helper function: Tags a text object as a JSON-type



19
20
21
22
23
# File 'lib/belphanior/servant/servant_config.rb', line 19

def self.write_config_file(file_path, config)
  out = File.open(file_path, "w")
  out.write(config.to_json)
  out.close
end