Method: WebTranslateIt::Configuration#initialize

Defined in:
lib/web_translate_it/configuration.rb

#initialize(root_path = Rails.root, path_to_config_file = '.wti') ⇒ Configuration

Load configuration file from the path.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/web_translate_it/configuration.rb', line 16

def initialize(root_path = Rails.root, path_to_config_file = '.wti') # rubocop:todo Metrics/AbcSize, Metrics/MethodLength
  self.path_to_config_file = path_to_config_file
  self.path           = root_path
  self.logger         = logger
  if File.exist?(File.expand_path(path_to_config_file, path))
    self.api_key        = ENV.fetch('WTI_PROJECT_API_KEY') { configuration['api_key'] }
    self.before_pull    = configuration['before_pull']
    self.after_pull     = configuration['after_pull']
    self.before_push    = configuration['before_push']
    self.after_push     = configuration['after_push']
    self.ignore_files   = configuration['ignore_files']
    project_info = JSON.parse WebTranslateIt::Project.fetch_info(api_key)
    self.ignore_locales = locales_to_ignore(configuration)
    self.needed_locales = locales_needed(configuration)
    self.files = files_from_project(project_info['project'])
    self.source_locale = source_locale_from_project(project_info['project'])
    self.target_locales = target_locales_from_project(project_info['project'])
    self.project_name = project_info['project']['name']
  else
    puts StringUtil.failure("\nNo configuration file found in #{File.expand_path(path_to_config_file, path)}")
    exit(1)
  end
end