Module: I18n::Tasks::Command::Commands::Data

Includes:
I18n::Tasks::Command::Collection
Included in:
I18n::Tasks::Commands
Defined in:
lib/i18n/tasks/command/commands/data.rb

Instance Method Summary collapse

Methods included from I18n::Tasks::Command::Collection

included

Instance Method Details

#check_normalized(opt) ⇒ Object



29
30
31
32
33
# File 'lib/i18n/tasks/command/commands/data.rb', line 29

def check_normalized(opt)
  non_normalized = i18n.non_normalized_paths locales: opt[:locales]
  terminal_report.check_normalized_results(non_normalized)
  :exit1 unless non_normalized.empty?
end

#data(opt = {}) ⇒ Object



68
69
70
# File 'lib/i18n/tasks/command/commands/data.rb', line 68

def data(opt = {})
  print_forest i18n.data_forest(opt[:locales]), opt
end

#data_merge(opt = {}) ⇒ Object



77
78
79
80
81
# File 'lib/i18n/tasks/command/commands/data.rb', line 77

def data_merge(opt = {})
  forest = merge_forests_stdin_and_pos!(opt)
  merged = i18n.data.merge!(forest)
  print_forest merged, opt
end

#data_remove(opt = {}) ⇒ Object



99
100
101
102
103
# File 'lib/i18n/tasks/command/commands/data.rb', line 99

def data_remove(opt = {})
  removed = i18n.data.remove_by_key!(forest_pos_or_stdin!(opt))
  log_stderr 'Removed:'
  print_forest removed, opt
end

#data_write(opt = {}) ⇒ Object



88
89
90
91
92
# File 'lib/i18n/tasks/command/commands/data.rb', line 88

def data_write(opt = {})
  forest = forest_pos_or_stdin!(opt)
  i18n.data.write forest
  print_forest forest, opt
end

#mv(opt = {}) ⇒ Object



38
39
40
41
42
43
44
45
46
47
# File 'lib/i18n/tasks/command/commands/data.rb', line 38

def mv(opt = {})
  fail CommandError, 'requires FROM_KEY_PATTERN and TO_KEY_PATTERN' if opt[:arguments].size < 2

  from_pattern = opt[:arguments].shift
  to_pattern = opt[:arguments].shift
  forest = i18n.data_forest
  results = forest.mv_key!(compile_key_pattern(from_pattern), to_pattern, root: false)
  i18n.data.write forest
  terminal_report.mv_results results
end

#normalize(opt = {}) ⇒ Object



19
20
21
22
# File 'lib/i18n/tasks/command/commands/data.rb', line 19

def normalize(opt = {})
  i18n.normalize_store! locales: opt[:locales],
                        force_pattern_router: opt[:pattern_router]
end

#rm(opt = {}) ⇒ Object



52
53
54
55
56
57
58
59
60
61
# File 'lib/i18n/tasks/command/commands/data.rb', line 52

def rm(opt = {})
  fail CommandError, 'requires KEY_PATTERN' if opt[:arguments].empty?

  forest = i18n.data_forest
  results = opt[:arguments].each_with_object({}) do |key_pattern, h|
    h.merge! forest.mv_key!(compile_key_pattern(key_pattern), '', root: false)
  end
  i18n.data.write forest
  terminal_report.mv_results results
end