Class: Icapps::Translations::Configuration
- Inherits:
-
Object
- Object
- Icapps::Translations::Configuration
- Defined in:
- lib/icapps/translations/configuration.rb
Instance Attribute Summary collapse
-
#default_language ⇒ Object
readonly
Returns the value of attribute default_language.
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
-
#project_key ⇒ Object
readonly
Returns the value of attribute project_key.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Class Method Summary collapse
- .android_initial_content ⇒ Object
- .common_initial_content ⇒ Object
- .create ⇒ Object
- .exists? ⇒ Boolean
- .filename ⇒ Object
- .initial_content ⇒ Object
- .options ⇒ Object
- .path ⇒ Object
Instance Method Summary collapse
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
- #validate ⇒ Object
Constructor Details
#initialize ⇒ Configuration
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_language ⇒ Object (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 |
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
8 9 10 |
# File 'lib/icapps/translations/configuration.rb', line 8 def filename @filename end |
#project_key ⇒ Object (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 |
#url ⇒ Object (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_content ⇒ Object
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_content ⇒ Object
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 |
.create ⇒ Object
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
23 24 25 |
# File 'lib/icapps/translations/configuration.rb', line 23 def exists? File.exist?(path) end |
.filename ⇒ Object
31 32 33 |
# File 'lib/icapps/translations/configuration.rb', line 31 def filename '.translations' end |
.initial_content ⇒ Object
39 40 41 |
# File 'lib/icapps/translations/configuration.rb', line 39 def initial_content ::Icapps::Translations.android? ? android_initial_content : common_initial_content end |
.options ⇒ Object
35 36 37 |
# File 'lib/icapps/translations/configuration.rb', line 35 def ::Icapps::Translations. end |
.path ⇒ Object
27 28 29 |
# File 'lib/icapps/translations/configuration.rb', line 27 def path File.join(Dir.pwd, filename) end |
Instance Method Details
#validate ⇒ Object
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 |