Class: Guard::I18nJson
- Inherits:
-
Plugin
- Object
- Plugin
- Guard::I18nJson
- Defined in:
- lib/guard/i18n_json.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
- #error(message) ⇒ Object
- #export_files(changes = nil) ⇒ Object
- #info(message) ⇒ Object
-
#initialize(options = {}) ⇒ I18nJson
constructor
A new instance of I18nJson.
- #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 = {}) ⇒ I18nJson
Returns a new instance of I18nJson.
14 15 16 17 18 |
# File 'lib/guard/i18n_json.rb', line 14 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.
12 13 14 |
# File 'lib/guard/i18n_json.rb', line 12 def config_file @config_file end |
#current_thread ⇒ Object (readonly)
Returns the value of attribute current_thread.
12 13 14 |
# File 'lib/guard/i18n_json.rb', line 12 def current_thread @current_thread end |
#require_file ⇒ Object (readonly)
Returns the value of attribute require_file.
12 13 14 |
# File 'lib/guard/i18n_json.rb', line 12 def require_file @require_file end |
Instance Method Details
#error(message) ⇒ Object
71 72 73 |
# File 'lib/guard/i18n_json.rb', line 71 def error() ::Guard::UI.error "[guard-i18n-json] #{}" end |
#export_files(changes = nil) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/guard/i18n_json.rb', line 48 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 require @require_file ::I18nJSON.call(config_file: @config_file) end current_thread.join end |
#info(message) ⇒ Object
75 76 77 |
# File 'lib/guard/i18n_json.rb', line 75 def info() ::Guard::UI.info "[guard-i18n-json] #{}" end |
#reload ⇒ Object
28 29 30 |
# File 'lib/guard/i18n_json.rb', line 28 def reload export_files end |
#run_all ⇒ Object
32 33 34 |
# File 'lib/guard/i18n_json.rb', line 32 def run_all export_files end |
#run_on_additions(paths) ⇒ Object
36 37 38 |
# File 'lib/guard/i18n_json.rb', line 36 def run_on_additions(paths) export_files(paths) end |
#run_on_modifications(paths) ⇒ Object
40 41 42 |
# File 'lib/guard/i18n_json.rb', line 40 def run_on_modifications(paths) export_files(paths) end |
#run_on_removals(paths) ⇒ Object
44 45 46 |
# File 'lib/guard/i18n_json.rb', line 44 def run_on_removals(paths) export_files(paths) end |
#start ⇒ Object
20 21 22 |
# File 'lib/guard/i18n_json.rb', line 20 def start export_files end |
#stop ⇒ Object
24 25 26 |
# File 'lib/guard/i18n_json.rb', line 24 def stop current_thread&.exit end |
#validate_file(key, file) ⇒ Object
64 65 66 67 68 69 |
# File 'lib/guard/i18n_json.rb', line 64 def validate_file(key, file) return true if file && File.file?(file) error("#{key.inspect} must be a file") false end |