Class: ToptranslationCli::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/toptranslation_cli/configuration.rb

Constant Summary collapse

FILENAME =
'.toptranslation.yml'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



9
10
11
12
13
# File 'lib/toptranslation_cli/configuration.rb', line 9

def initialize
  @files_base_url = 'https://files.toptranslation.com'
  @api_base_url = 'https://api.toptranslation.com'
  @verbose = !ENV['VERBOSE'].nil?
end

Instance Attribute Details

#access_tokenObject

Returns the value of attribute access_token.



5
6
7
# File 'lib/toptranslation_cli/configuration.rb', line 5

def access_token
  @access_token
end

#api_base_urlObject

Returns the value of attribute api_base_url.



5
6
7
# File 'lib/toptranslation_cli/configuration.rb', line 5

def api_base_url
  @api_base_url
end

#filesObject

Returns the value of attribute files.



5
6
7
# File 'lib/toptranslation_cli/configuration.rb', line 5

def files
  @files
end

#files_base_urlObject

Returns the value of attribute files_base_url.



5
6
7
# File 'lib/toptranslation_cli/configuration.rb', line 5

def files_base_url
  @files_base_url
end

#project_identifierObject

Returns the value of attribute project_identifier.



5
6
7
# File 'lib/toptranslation_cli/configuration.rb', line 5

def project_identifier
  @project_identifier
end

#verboseObject

Returns the value of attribute verbose.



5
6
7
# File 'lib/toptranslation_cli/configuration.rb', line 5

def verbose
  @verbose
end

Instance Method Details

#exist?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/toptranslation_cli/configuration.rb', line 36

def exist?
  File.exist?(FILENAME)
end

#loadObject



15
16
17
18
19
20
21
# File 'lib/toptranslation_cli/configuration.rb', line 15

def load
  @project_identifier = configuration['project_identifier']
  @access_token = configuration['access_token']
  @files_base_url = configuration['files_base_url'] || @files_base_url
  @api_base_url = configuration['api_base_url'] || @api_base_url
  @files = configuration['files'] || []
end

#saveObject



23
24
25
26
27
28
# File 'lib/toptranslation_cli/configuration.rb', line 23

def save
  File.open(FILENAME, 'w') do |file|
    # Psych can't stringify keys so we dump it to json before dumping to yml
    Psych.dump(JSON.parse(configuration_hash.to_json), file)
  end
end

#use_examplesObject



30
31
32
33
34
# File 'lib/toptranslation_cli/configuration.rb', line 30

def use_examples
  @project_identifier = '<PROJECT_IDENTIFIER>'
  @access_token = '<YOUR_ACCESS_TOKEN>'
  @files = ['config/locales/{locale_code}/**/*.yml']
end