Class: I18n::Migrations::Config
- Inherits:
-
Object
- Object
- I18n::Migrations::Config
- Defined in:
- lib/i18n/migrations/config.rb
Constant Summary collapse
- CONFIG_FILE_NAME =
'.i18n-migrations.yml'
- DEFAULT_CONCURRENCY =
4
- DEFAULT_WAIT_SECONDS =
0
- CROWD_TRANSLATE_BACKEND =
'crowd_translate'
- GOOGLE_SPREADSHEET_BACKEND =
'google_spreadsheets'
- VALID_BACKENDS =
[CROWD_TRANSLATE_BACKEND, GOOGLE_SPREADSHEET_BACKEND]
Class Method Summary collapse
Instance Method Summary collapse
- #backend ⇒ Object
- #concurrency ⇒ Object
- #crowd_translate? ⇒ Boolean
- #do_not_translate(locale) ⇒ Object
- #google_service_account_key_path ⇒ Object
- #google_spreadsheet(locale) ⇒ Object
- #google_spreadsheet? ⇒ Boolean
- #google_translate_api_key ⇒ Object
-
#initialize(config_file_name = CONFIG_FILE_NAME) ⇒ Config
constructor
A new instance of Config.
- #locales_dir ⇒ Object
- #main_locale ⇒ Object
- #migration_dir ⇒ Object
- #other_locales ⇒ Object
- #push_concurrency ⇒ Object
- #read! ⇒ Object
- #wait_seconds ⇒ Object
Constructor Details
#initialize(config_file_name = CONFIG_FILE_NAME) ⇒ Config
Returns a new instance of Config.
13 14 15 |
# File 'lib/i18n/migrations/config.rb', line 13 def initialize(config_file_name = CONFIG_FILE_NAME) @config_file_name = config_file_name end |
Class Method Details
.copy_default_config_file(dir) ⇒ Object
98 99 100 101 102 |
# File 'lib/i18n/migrations/config.rb', line 98 def self.copy_default_config_file(dir) File.open(File.join(dir, CONFIG_FILE_NAME), 'w') do |f| f << File.read(File.join(File.dirname(__FILE__), '../../../.i18n-migrations.default.yml')) end end |
Instance Method Details
#backend ⇒ Object
29 30 31 32 33 |
# File 'lib/i18n/migrations/config.rb', line 29 def backend value = get_value(:backend) raise ArgumentError, "Backend must be one of #{VALID_BACKENDS}" unless VALID_BACKENDS.include?(value) value end |
#concurrency ⇒ Object
65 66 67 |
# File 'lib/i18n/migrations/config.rb', line 65 def concurrency get_value(:concurrency, DEFAULT_CONCURRENCY) end |
#crowd_translate? ⇒ Boolean
35 36 37 |
# File 'lib/i18n/migrations/config.rb', line 35 def crowd_translate? backend == CROWD_TRANSLATE_BACKEND end |
#do_not_translate(locale) ⇒ Object
55 56 57 58 59 |
# File 'lib/i18n/migrations/config.rb', line 55 def do_not_translate(locale) return {} if locale.to_s == main_locale get_value([:other_locales, locale])['do_not_translate'] || {} end |
#google_service_account_key_path ⇒ Object
47 48 49 |
# File 'lib/i18n/migrations/config.rb', line 47 def google_service_account_key_path get_file(:google_service_account_key_path) end |
#google_spreadsheet(locale) ⇒ Object
51 52 53 |
# File 'lib/i18n/migrations/config.rb', line 51 def google_spreadsheet(locale) get_value([:other_locales, locale, :google_spreadsheet]) end |
#google_spreadsheet? ⇒ Boolean
39 40 41 |
# File 'lib/i18n/migrations/config.rb', line 39 def google_spreadsheet? backend == GOOGLE_SPREADSHEET_BACKEND end |
#google_translate_api_key ⇒ Object
61 62 63 |
# File 'lib/i18n/migrations/config.rb', line 61 def google_translate_api_key get_value(:google_translate_api_key, ENV['GOOGLE_TRANSLATE_API_KEY']) end |
#locales_dir ⇒ Object
21 22 23 |
# File 'lib/i18n/migrations/config.rb', line 21 def locales_dir get_file(:locales_dir) end |
#main_locale ⇒ Object
25 26 27 |
# File 'lib/i18n/migrations/config.rb', line 25 def main_locale get_value(:main_locale) end |
#migration_dir ⇒ Object
17 18 19 |
# File 'lib/i18n/migrations/config.rb', line 17 def migration_dir get_file(:migration_dir) end |
#other_locales ⇒ Object
43 44 45 |
# File 'lib/i18n/migrations/config.rb', line 43 def other_locales get_value(:other_locales).keys end |
#push_concurrency ⇒ Object
69 70 71 |
# File 'lib/i18n/migrations/config.rb', line 69 def push_concurrency get_value(:push_concurrency, concurrency) end |
#read! ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/i18n/migrations/config.rb', line 77 def read! yaml_file = find_config_file(@config_file_name) unless yaml_file STDERR.puts "Can't find a #{@config_file_name} file. Try running 'i18n-migrations setup'" exit(1) end @root_dir = File.dirname(yaml_file) @config = begin YAML::load(File.read(yaml_file)) rescue Psych::SyntaxError STDERR.puts("YAML configuration file contains invalid syntax.") STDERR.puts($!.) exit(1) end # todo check for required keys self end |
#wait_seconds ⇒ Object
73 74 75 |
# File 'lib/i18n/migrations/config.rb', line 73 def wait_seconds get_value(:wait_seconds, DEFAULT_WAIT_SECONDS) end |