Class: Guard::I18nJson

Inherits:
Plugin
  • Object
show all
Defined in:
lib/guard/i18n_json.rb,
lib/guard/i18n_json/version.rb

Constant Summary collapse

VERSION =
"0.0.1"

Instance Attribute Summary collapse

Instance Method Summary collapse

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(options = {})
  @config_file = options.delete(:config_file)
  @require_file = options.delete(:require_file)
  super
end

Instance Attribute Details

#config_fileObject (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_threadObject (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_fileObject (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(message)
  ::Guard::UI.error "[guard-i18n-json] #{message}"
end

#export_filesObject



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

#reloadObject



28
29
30
# File 'lib/guard/i18n_json.rb', line 28

def reload
  export_files
end

#run_allObject



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

#startObject



20
21
22
# File 'lib/guard/i18n_json.rb', line 20

def start
  export_files
end

#stopObject



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