Class: Guard::I18njs
- Inherits:
-
Plugin
- Object
- Plugin
- Guard::I18njs
- Defined in:
- lib/guard/i18n-js.rb
Instance Attribute Summary collapse
-
#config_file ⇒ Object
readonly
Returns the value of attribute config_file.
-
#current_thread ⇒ Object
readonly
Returns the value of attribute current_thread.
-
#require_file ⇒ Object
readonly
Returns the value of attribute require_file.
Instance Method Summary collapse
- #capture ⇒ Object
- #error(message) ⇒ Object
- #export_files(changes = nil) ⇒ Object
- #info(message) ⇒ Object
-
#initialize(options = {}) ⇒ I18njs
constructor
A new instance of I18njs.
- #reload ⇒ Object
- #run_all ⇒ Object
- #run_on_additions(paths) ⇒ Object
- #run_on_modifications(paths) ⇒ Object
- #run_on_removals(paths) ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
- #validate_file(key, file) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ I18njs
Returns a new instance of I18njs.
13 14 15 16 17 |
# File 'lib/guard/i18n-js.rb', line 13 def initialize( = {}) @config_file = .delete(:config_file) @require_file = .delete(:require_file) super end |
Instance Attribute Details
#config_file ⇒ Object (readonly)
Returns the value of attribute config_file.
11 12 13 |
# File 'lib/guard/i18n-js.rb', line 11 def config_file @config_file end |
#current_thread ⇒ Object (readonly)
Returns the value of attribute current_thread.
11 12 13 |
# File 'lib/guard/i18n-js.rb', line 11 def current_thread @current_thread end |
#require_file ⇒ Object (readonly)
Returns the value of attribute require_file.
11 12 13 |
# File 'lib/guard/i18n-js.rb', line 11 def require_file @require_file end |
Instance Method Details
#capture ⇒ Object
70 71 72 73 74 75 76 77 78 |
# File 'lib/guard/i18n-js.rb', line 70 def capture original = $stdout $stdout = StringIO.new yield rescue StandardError # noop ensure $stdout = original end |
#error(message) ⇒ Object
87 88 89 |
# File 'lib/guard/i18n-js.rb', line 87 def error() ::Guard::UI.error "[i18n-js] #{}" end |
#export_files(changes = nil) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/guard/i18n-js.rb', line 47 def export_files(changes = nil) return unless validate_file(:config_file, config_file) return unless validate_file(:require_file, require_file) current_thread&.exit info("Changes detected: #{changes.join(', ')}") if changes @current_thread = Thread.new do capture do system "i18n", "export", "--config", config_file.to_s, "--require", require_file.to_s, "--quiet" end end current_thread.join end |
#info(message) ⇒ Object
91 92 93 |
# File 'lib/guard/i18n-js.rb', line 91 def info() ::Guard::UI.info "[i18n-js] #{}" end |
#reload ⇒ Object
27 28 29 |
# File 'lib/guard/i18n-js.rb', line 27 def reload export_files end |
#run_all ⇒ Object
31 32 33 |
# File 'lib/guard/i18n-js.rb', line 31 def run_all export_files end |
#run_on_additions(paths) ⇒ Object
35 36 37 |
# File 'lib/guard/i18n-js.rb', line 35 def run_on_additions(paths) export_files(paths) end |
#run_on_modifications(paths) ⇒ Object
39 40 41 |
# File 'lib/guard/i18n-js.rb', line 39 def run_on_modifications(paths) export_files(paths) end |
#run_on_removals(paths) ⇒ Object
43 44 45 |
# File 'lib/guard/i18n-js.rb', line 43 def run_on_removals(paths) export_files(paths) end |
#start ⇒ Object
19 20 21 |
# File 'lib/guard/i18n-js.rb', line 19 def start export_files end |
#stop ⇒ Object
23 24 25 |
# File 'lib/guard/i18n-js.rb', line 23 def stop current_thread&.exit end |
#validate_file(key, file) ⇒ Object
80 81 82 83 84 85 |
# File 'lib/guard/i18n-js.rb', line 80 def validate_file(key, file) return true if file && File.file?(file) error("#{key.inspect} must be a file") false end |