Class: Icapps::Translations::Configuration

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



57
58
59
# File 'lib/icapps/translations/configuration.rb', line 57

def initialize
  read_config if Configuration.exists?
end

Instance Attribute Details

#default_languageObject (readonly)

Returns the value of attribute default_language.



10
11
12
# File 'lib/icapps/translations/configuration.rb', line 10

def default_language
  @default_language
end

#filenameObject (readonly)

Returns the value of attribute filename.



8
9
10
# File 'lib/icapps/translations/configuration.rb', line 8

def filename
  @filename
end

#project_keyObject (readonly)

Returns the value of attribute project_key.



9
10
11
# File 'lib/icapps/translations/configuration.rb', line 9

def project_key
  @project_key
end

#urlObject (readonly)

Returns the value of attribute url.



7
8
9
# File 'lib/icapps/translations/configuration.rb', line 7

def url
  @url
end

Class Method Details

.android_initial_contentObject



43
44
45
46
# File 'lib/icapps/translations/configuration.rb', line 43

def android_initial_content
  common_initial_content.merge!(filename: 'strings.xml',
                                default_language: 'en')
end

.common_initial_contentObject



48
49
50
51
52
53
54
# File 'lib/icapps/translations/configuration.rb', line 48

def common_initial_content
  {
    url:         'http://your_url.com',
    filename:    'Localizable.strings',
    project_key: 'YourProjectKey'
  }
end

.createObject



13
14
15
16
17
18
19
20
21
# File 'lib/icapps/translations/configuration.rb', line 13

def create
  if exists?
    puts "[WARNING] Configuration already exists at '#{path}'.".colorize(:yellow)
    return
  end

  File.open(path, 'w') { |f| f.write(initial_content.to_yaml) }
  puts "[MESSAGE] Configuration created at '#{path}'.".colorize(:green)
end

.exists?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/icapps/translations/configuration.rb', line 23

def exists?
  File.exist?(path)
end

.filenameObject



31
32
33
# File 'lib/icapps/translations/configuration.rb', line 31

def filename
  '.translations'
end

.initial_contentObject



39
40
41
# File 'lib/icapps/translations/configuration.rb', line 39

def initial_content
  ::Icapps::Translations.android? ? android_initial_content : common_initial_content
end

.optionsObject



35
36
37
# File 'lib/icapps/translations/configuration.rb', line 35

def options
  ::Icapps::Translations.options
end

.pathObject



27
28
29
# File 'lib/icapps/translations/configuration.rb', line 27

def path
  File.join(Dir.pwd, filename)
end

Instance Method Details

#validateObject



61
62
63
64
65
# File 'lib/icapps/translations/configuration.rb', line 61

def validate
  abort '[ERROR] You need to provide a project key in the .translations configuration file.'.colorize(:red) unless @project_key
  abort '[ERROR] You need to provide an url in the .translations configuration file.'.colorize(:red) unless @url
  abort '[ERROR] You need to provide a default filename in the .translations configuration file.'.colorize(:red) unless @filename
end