i18n-migrations 2.0.2 → 2.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bb3ceb9342d7783602ef5140a652c478be028f86ef9c00189716e19a0510d906
4
- data.tar.gz: 77d1390534f26893cffaccee141d87eda064c3e0893b7388e6afcf282637fe8d
3
+ metadata.gz: 81cdab3c95ecdf3eadada65b83f94e51733cca841bda8862def4150f3ca182ce
4
+ data.tar.gz: bcce6ac35266718cc3e49ec7289cba1dedd8f0e012c916a82c1fe323390034a7
5
5
  SHA512:
6
- metadata.gz: 0b7ea99af87e5e72d377e163ee56de47b71d74c118032fd1528f63ee5b170f046b9562ed6d5767ee64d38f806e69b5496e1763cd2c02ee59a1145e7723e8fb57
7
- data.tar.gz: da8afa4e69a472f59cad457800b448b1bd00d63b6b34912045649238dace69ee7088c26eafb22ce05e1d21fb5e5ee3ce907814e389ce91e2bf40be18bb2851fb
6
+ metadata.gz: 65f1fd2c2b047d76b74f6ca85699d8ee5e618b9d35a8e4d24d19a42c851833cfd4cc4f22668f31aecc9eaa2806fffa4801e262ac6193944497fadc48c3c4dcc3
7
+ data.tar.gz: e041b073626e8546226677bfb927a85a6c3235a233efe33a992b6e7dcb1da2f67c02469552b328b09e6b06ca642fd8579ec378fa08d605a5086342ec75cce5b6
@@ -10,59 +10,60 @@ def extract_option(name)
10
10
  !!ARGV.delete(name)
11
11
  end
12
12
 
13
- case ARGV.shift
14
- when 'setup'
15
- puts 'Where should we create a default config file? [.]'
16
- dir = gets.chomp
17
- dir = dir == '' ? '.' : dir
18
- file = I18n::Migrations::Config.copy_default_config_file(dir)
19
-
20
- puts 'You will need to configure this file before you can get going.'
21
- puts File.expand_path(file)
22
-
23
- when 'new'
24
- name = ARGV.shift
25
- if name
26
- migrator.new_migration name
27
- else
28
- STDERR.puts 'Usage: im new [name]'
29
- exit 1
30
- end
31
-
32
- when 'migrate'
33
- migrator.migrate(ARGV[0] || 'all')
34
-
35
- when 'rollback'
36
- migrator.rollback(ARGV[0] || 'all')
37
-
38
- when 'redo'
39
- migrator.rollback(ARGV[0] || 'all')
40
- migrator.migrate(ARGV[0] || 'all')
41
-
42
- when 'pull'
43
- migrator.pull(ARGV[0] || 'all')
13
+ begin
14
+ case ARGV.shift
15
+ when 'setup'
16
+ puts 'Where should we create a default config file? [.]'
17
+ dir = gets.chomp
18
+ dir = dir == '' ? '.' : dir
19
+ file = I18n::Migrations::Config.copy_default_config_file(dir)
20
+
21
+ puts 'You will need to configure this file before you can get going.'
22
+ puts File.expand_path(file)
23
+
24
+ when 'new'
25
+ name = ARGV.shift
26
+ if name
27
+ migrator.new_migration name
28
+ else
29
+ STDERR.puts 'Usage: im new [name]'
30
+ exit 1
31
+ end
32
+
33
+ when 'migrate'
34
+ migrator.migrate(ARGV[0] || 'all')
35
+
36
+ when 'rollback'
37
+ migrator.rollback(ARGV[0] || 'all')
38
+
39
+ when 'redo'
40
+ migrator.rollback(ARGV[0] || 'all')
41
+ migrator.migrate(ARGV[0] || 'all')
42
+
43
+ when 'pull'
44
+ migrator.pull(ARGV[0] || 'all')
45
+
46
+ when 'push'
47
+ force = extract_option('-f')
48
+ migrator.push(ARGV[0] || 'all', force)
49
+
50
+ when 'validate'
51
+ migrator.validate(ARGV[0] || 'all')
52
+
53
+ when 'new_locale'
54
+ locale = ARGV.shift
55
+ if locale
56
+ migrator.new_locale(locale)
57
+ else
58
+ STDERR.puts 'Usage: im new_locale [name]'
59
+ exit 1
60
+ end
61
+
62
+ when 'version'
63
+ migrator.version
44
64
 
45
- when 'push'
46
- force = extract_option('-f')
47
- migrator.push(ARGV[0] || 'all', force)
48
-
49
- when 'validate'
50
- migrator.validate(ARGV[0] || 'all')
51
-
52
- when 'new_locale'
53
- locale = ARGV.shift
54
- if locale
55
- migrator.new_locale(locale)
56
65
  else
57
- STDERR.puts 'Usage: im new_locale [name]'
58
- exit 1
59
- end
60
-
61
- when 'version'
62
- migrator.version
63
-
64
- else
65
- puts <<-USAGE
66
+ puts <<-USAGE
66
67
  Usage: i18n-migrate [command]
67
68
 
68
69
  Commands:
@@ -78,5 +79,9 @@ Commands:
78
79
  version - Print version of locales.
79
80
 
80
81
  i18n-migrations version #{I18n::Migrations::VERSION}
81
- USAGE
82
+ USAGE
83
+ end
84
+ rescue Exception
85
+ puts "Error\n#{$!.message}".red
86
+ exit 1
82
87
  end
@@ -53,9 +53,7 @@ module I18n
53
53
  begin
54
54
  client.put_migration(version: version, ruby_file: migrations.get_migration(version: version))
55
55
  rescue
56
- puts "There was an error updating migration:".red
57
- puts " #{migrations.migration_file(version: version)}".bold
58
- raise
56
+ raise CrowdTranslateError, "... while updating migration: #{migrations.migration_file(version: version)}\n#{$!.message}"
59
57
  end
60
58
  end
61
59
  end
@@ -4,16 +4,16 @@ require 'active_support/core_ext/object'
4
4
  module I18n
5
5
  module Migrations
6
6
  module Backends
7
+ class CrowdTranslateError < StandardError
8
+ end
9
+
7
10
  class CrowdTranslateClient
8
11
  def initialize
9
12
  token = ENV['CROWD_TRANSLATE_API_TOKEN']
10
13
  raise("You must define CROWD_TRANSLATE_API_TOKEN in order to talk to Crowd Translate") unless token.present?
11
14
 
12
- server = ENV['CROWD_TRANSLATE_SERVER'] || 'https://crowd-translate.herokuapp.com'
13
- @faraday = Faraday.new(
14
- url: "#{server}/api/v1",
15
- headers: { 'X-CrowdTranslateApiToken' => token },
16
- )
15
+ @server = ENV['CROWD_TRANSLATE_SERVER'] || 'https://crowd-translate.herokuapp.com'
16
+ @faraday = Faraday.new(url: base_url, headers: { 'X-CrowdTranslateApiToken' => token })
17
17
  end
18
18
 
19
19
  def get_locale_file(locale_code)
@@ -37,15 +37,15 @@ module I18n
37
37
 
38
38
  def get(path)
39
39
  puts "GET #{path}".bold
40
- parse_response @faraday.get path
40
+ parse_response 'GET', path, @faraday.get(path)
41
41
  end
42
42
 
43
43
  def put(path, params = {})
44
44
  puts "PUT #{path} #{params.to_s[0..50]}#{'...' if params.to_s.length > 50}".bold
45
- parse_response @faraday.put path, params
45
+ parse_response 'PUT', path, @faraday.put(path, params)
46
46
  end
47
47
 
48
- def parse_response(response)
48
+ def parse_response(method, path, response)
49
49
  if response.success?
50
50
  response.body
51
51
  else
@@ -54,9 +54,13 @@ module I18n
54
54
  rescue
55
55
  response.body
56
56
  end
57
- raise error
57
+ raise CrowdTranslateError, "... while calling #{method} #{File.join(base_url, path)}\n#{error}"
58
58
  end
59
59
  end
60
+
61
+ def base_url
62
+ "#{@server}/api/v1"
63
+ end
60
64
  end
61
65
  end
62
66
  end
@@ -72,7 +72,7 @@ end
72
72
 
73
73
  def pull(locale_or_all)
74
74
  each_locale(locale_or_all) do |locale|
75
- next if locale.main_locale?
75
+ # next if locale.main_locale?
76
76
  backend.pull(locale)
77
77
  end
78
78
  end
@@ -104,9 +104,23 @@ end
104
104
  end
105
105
  end
106
106
 
107
+ private def report_locale_on_error(locale, &block)
108
+ begin
109
+ block.call locale
110
+ rescue Backends::CrowdTranslateError
111
+ puts "Error\n... while working with #{locale.name}\n#{$!.message}".red
112
+ # we want a readable error for our users, and the error happened in an external system,
113
+ # so don't give them a stack trace
114
+ rescue
115
+ puts "Error\n... while working with #{locale.name}\n#{$!.message}".red
116
+ raise
117
+ end
118
+ end
119
+
107
120
  private def each_locale(name = 'all',
108
121
  async: true,
109
- concurrency: config.concurrency)
122
+ concurrency: config.concurrency,
123
+ &block)
110
124
  locale_names = name == 'all' ? all_locale_names : [name]
111
125
 
112
126
  if async
@@ -114,13 +128,13 @@ end
114
128
  locale_names.each_slice(concurrency) do |some_locale_names|
115
129
  threads = some_locale_names.map do |l|
116
130
  locale = locale_for(l)
117
- Thread.new { yield locale }
131
+ Thread.new { report_locale_on_error(locale, &block) }
118
132
  end
119
133
  threads.each(&:join)
120
134
  end
121
135
  else
122
136
  locale_names.each do |l|
123
- yield locale_for(l)
137
+ report_locale_on_error(locale_for(l), &block)
124
138
  end
125
139
  end
126
140
  end
@@ -1,5 +1,5 @@
1
1
  module I18n
2
2
  module Migrations
3
- VERSION = "2.0.2"
3
+ VERSION = "2.0.3"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: i18n-migrations
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.2
4
+ version: 2.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Lightsmith
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-03-23 00:00:00.000000000 Z
11
+ date: 2020-07-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler