i18n-json 0.0.2 → 0.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: b81e3b3409e00ed7ddcc14ca89fb4a3d156e994fc3726e0b7497b830b79d7283
4
- data.tar.gz: d70e1fde67b202d8615f7664f24badd060b15be60193202813ef9234ab6655d2
3
+ metadata.gz: 666dca9e8285a7921ff0b31ced86105b24fcb23a217c52994d0ee56a0785c45e
4
+ data.tar.gz: b4abd12f837a0349703f6e542804d89348c3b852a46a110c463a2fe133cddfd5
5
5
  SHA512:
6
- metadata.gz: 38b833a5607098230ebb72afcfd26350d3fca1eaf48efa3b011a1266b32f461344c93cefea6de1a7f30973366de61992f4adb7091b3f9d792108d2cc8b74acd5
7
- data.tar.gz: 4ea046aa5a7611a68698f863fa140223ed0853b02b4d3c6324980b2b50e8bdfc3a0d528cb7f0c200054332ddd83775ddebe5bfcb8fe1898d94ef72df13ba9745
6
+ metadata.gz: b168e9286da7f3cf86fedd3611a4fec65cf970bd32f9b4fab9a185df8b2fae1fd30658177c4466e997b7f0c45fe36525fb219816f5ffa57769dc5d8af01eb6d7
7
+ data.tar.gz: 2810edd4f35a43aef1e076875ffdb257d6b79999d2204e32f18ef5cff43488a0923b1f0fd1e22182408d432e0a179c9e16c2763392676f08afc2e180834c8ddb
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "benchmark"
4
+
3
5
  module I18nJSON
4
6
  class CLI
5
7
  class ExportCommand < Command
@@ -30,7 +32,16 @@ module I18nJSON
30
32
  end
31
33
  end
32
34
 
33
- command do
35
+ command do # rubocop:disable Metrics/BlockLength
36
+ set_defaults!
37
+
38
+ ui.stdout_print("=> config file:", options[:config_file].inspect)
39
+ ui.stdout_print("=> require file:", options[:require_file].inspect)
40
+
41
+ unless options[:config_file]
42
+ ui.fail_with("=> ERROR: you need to specify the config file")
43
+ end
44
+
34
45
  config_file = File.expand_path(options[:config_file])
35
46
 
36
47
  if options[:require_file]
@@ -38,15 +49,50 @@ module I18nJSON
38
49
  end
39
50
 
40
51
  unless File.file?(config_file)
41
- ui.fail_with("ERROR: config file doesn't exist at #{config_file}")
52
+ ui.fail_with(
53
+ "=> ERROR: config file doesn't exist at",
54
+ config_file.inspect
55
+ )
42
56
  end
43
57
 
44
58
  if require_file && !File.file?(require_file)
45
- ui.fail_with("ERROR: require file doesn't exist at #{require_file}")
59
+ ui.fail_with(
60
+ "=> ERROR: require file doesn't exist at",
61
+ require_file.inspect
62
+ )
63
+ end
64
+
65
+ time = Benchmark.realtime do
66
+ load_require_file!(require_file) if require_file
67
+ I18nJSON.call(config_file: config_file)
46
68
  end
47
69
 
48
- require_without_warnings(require_file) if require_file
49
- I18nJSON.call(config_file: config_file)
70
+ ui.stdout_print("=> done in #{time.round(2)}s")
71
+ end
72
+
73
+ private def set_defaults!
74
+ config_file = "./config/i18n.yml"
75
+ require_file = "./config/environment.rb"
76
+
77
+ options[:config_file] ||= config_file if File.file?(config_file)
78
+ options[:require_file] ||= require_file if File.file?(require_file)
79
+ end
80
+
81
+ private def load_require_file!(require_file)
82
+ require_without_warnings(require_file)
83
+ rescue Exception => error # rubocop:disable Lint/RescueException
84
+ ui.stderr_print("=> ERROR: couldn't load",
85
+ options[:require_file].inspect)
86
+ ui.fail_with(
87
+ "\n#{error_description(error)}\n#{error.backtrace.join("\n")}"
88
+ )
89
+ end
90
+
91
+ private def error_description(error)
92
+ [
93
+ error.class.name,
94
+ error.message
95
+ ].reject(&:empty?).join(" => ")
50
96
  end
51
97
 
52
98
  private def require_without_warnings(path)
@@ -8,20 +8,20 @@ module I18nJSON
8
8
  @stderr = stderr
9
9
  end
10
10
 
11
- def stdout_print(message)
12
- @stdout << "#{message}\n"
11
+ def stdout_print(*message)
12
+ @stdout << "#{message.join(' ')}\n"
13
13
  end
14
14
 
15
- def stderr_print(message)
16
- @stderr << "#{message}\n"
15
+ def stderr_print(*message)
16
+ @stderr << "#{message.join(' ')}\n"
17
17
  end
18
18
 
19
- def fail_with(message)
19
+ def fail_with(*message)
20
20
  stderr_print(message)
21
21
  exit(1)
22
22
  end
23
23
 
24
- def exit_with(message)
24
+ def exit_with(*message)
25
25
  stdout_print(message)
26
26
  exit(0)
27
27
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module I18nJSON
4
- VERSION = "0.0.2"
4
+ VERSION = "0.0.3"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: i18n-json
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nando Vieira
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-05-23 00:00:00.000000000 Z
11
+ date: 2021-05-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: glob
@@ -232,7 +232,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
232
232
  - !ruby/object:Gem::Version
233
233
  version: '0'
234
234
  requirements: []
235
- rubygems_version: 3.2.3
235
+ rubygems_version: 3.2.15
236
236
  signing_key:
237
237
  specification_version: 4
238
238
  summary: Export I18n translations to JSON.