Class: Guard::I18nJson
- Inherits:
-
Plugin
- Object
- Plugin
- Guard::I18nJson
- Defined in:
- lib/guard/i18n_json.rb,
lib/guard/i18n_json/version.rb
Constant Summary collapse
- VERSION =
"0.0.1"
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 ⇒ 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
69 70 71 |
# File 'lib/guard/i18n_json.rb', line 69 def error() ::Guard::UI.error "[guard-i18n-json] #{}" end |
#export_files ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/guard/i18n_json.rb', line 48 def export_files return unless validate_file(:config_file, config_file) return unless validate_file(:require_file, require_file) current_thread&.exit @current_thread = Thread.new do require @require_file ::I18nJSON.call(config_file: @config_file) end current_thread.join 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 end |
#run_on_modifications(_paths) ⇒ Object
40 41 42 |
# File 'lib/guard/i18n_json.rb', line 40 def run_on_modifications(_paths) export_files end |
#run_on_removals(_paths) ⇒ Object
44 45 46 |
# File 'lib/guard/i18n_json.rb', line 44 def run_on_removals(_paths) export_files 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
62 63 64 65 66 67 |
# File 'lib/guard/i18n_json.rb', line 62 def validate_file(key, file) return true if file && File.file?(file) error("#{key.inspect} must be a file") false end |