Class: Yamlt::Updater

Inherits:
Object
  • Object
show all
Defined in:
lib/yamlt/updater.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, target, translator_class: Yamlt::Updater.translator_class, config_path: "..") ⇒ Updater

Returns a new instance of Updater.



12
13
14
15
16
17
18
# File 'lib/yamlt/updater.rb', line 12

def initialize(source, target, translator_class: Yamlt::Updater.translator_class, config_path: "..")
  @source = source
  @target = target
  @translator = translator_class.new(state.language, loader.language)
  @config_path = config_path
  @config = config
end

Instance Attribute Details

#targetObject (readonly)

Returns the value of attribute target.



20
21
22
# File 'lib/yamlt/updater.rb', line 20

def target
  @target
end

Class Method Details

.translator_classObject



36
37
38
39
40
41
42
# File 'lib/yamlt/updater.rb', line 36

def self.translator_class
  if defined?(::Yamlt::CustomTranslator)
    ::Yamlt::CustomTranslator
  else
    ::Yamlt::Translator
  end
end

Instance Method Details

#callObject



22
23
24
25
26
27
28
29
30
# File 'lib/yamlt/updater.rb', line 22

def call
  of = File.new(target_updated, "w")

  state.lines.each do |line|
    of.puts format_line(line)
  end

  of.close
end

#rename_updatedObject



32
33
34
# File 'lib/yamlt/updater.rb', line 32

def rename_updated
  File.rename(target_updated, target)
end