Module: ConfigurationHelper

Included in:
TerrImporter::Application, TerrImporter::Application::ConfigurationLoader
Defined in:
lib/terrimporter/configuration_helper.rb

Instance Method Summary collapse

Instance Method Details

#backup_config_fileObject



3
4
5
6
# File 'lib/terrimporter/configuration_helper.rb', line 3

def backup_config_file
  LOG.debug "Backing up old configuration file to #{config_working_directory_path}.bak"
  FileUtils.mv(config_working_directory_path, config_working_directory_path + '.bak')
end

#base_config_pathObject



58
59
60
# File 'lib/terrimporter/configuration_helper.rb', line 58

def base_config_path
  File.join(File.dirname(__FILE__), '..', '..', 'config')
end

#config_default_nameObject



26
27
28
# File 'lib/terrimporter/configuration_helper.rb', line 26

def config_default_name
  'terrimporter.yml'
end

#config_example_pathObject



50
51
52
# File 'lib/terrimporter/configuration_helper.rb', line 50

def config_example_path
  File.join(base_config_path, config_default_name)
end

#config_search_pathsObject



34
35
36
37
38
39
40
# File 'lib/terrimporter/configuration_helper.rb', line 34

def config_search_paths
  [
      Dir.pwd,
      File.join(Dir.pwd, 'config'),
      File.join(Dir.pwd, '.config'),
  ]
end

#config_working_directory_exists?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/terrimporter/configuration_helper.rb', line 46

def config_working_directory_exists?
  File.exists? config_working_directory_path
end

#config_working_directory_pathObject



42
43
44
# File 'lib/terrimporter/configuration_helper.rb', line 42

def config_working_directory_path
  File.expand_path config_default_name
end

#create_config_file(application_url = nil) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/terrimporter/configuration_helper.rb', line 13

def create_config_file(application_url = nil)
  LOG.info "Creating configuration file..."
  FileUtils.cp(config_example_path, config_working_directory_path)

  unless application_url.nil?
    configuration = File.read(config_working_directory_path)
    configuration.gsub!(/application_url:.*$/, "application_url: #{application_url}")
    File.open(config_working_directory_path, 'w') { |f| f.write(configuration) }
  end

  LOG.info "done! You should take a look an edit it to your needs..."
end

#remove_config_fileObject



8
9
10
11
# File 'lib/terrimporter/configuration_helper.rb', line 8

def remove_config_file
  LOG.debug "Removing old configuration file"
  FileUtils.rm_f(config_working_directory_path) if File.exists? config_working_directory_path
end

#schema_default_nameObject



30
31
32
# File 'lib/terrimporter/configuration_helper.rb', line 30

def schema_default_name
  'schema.yml'
end

#schema_file_pathObject



54
55
56
# File 'lib/terrimporter/configuration_helper.rb', line 54

def schema_file_path
  File.join(base_config_path, schema_default_name)
end