Module: I18n::Tasks::Command::Commands::Tree

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

Constant Summary

Constants included from KeyPatternMatching

KeyPatternMatching::MATCH_NOTHING

Instance Method Summary collapse

Methods included from KeyPatternMatching

#compile_key_pattern, #compile_patterns_re, #key_pattern_re_body

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

included

Instance Method Details

#tree_convert(opt = {}) ⇒ Object



95
96
97
98
# File 'lib/i18n/tasks/command/commands/tree.rb', line 95

def tree_convert(opt = {})
  forest = forest_pos_or_stdin! opt.merge(format: opt[:from])
  print_forest forest, opt.merge(format: opt[:to])
end

#tree_filter(opts = {}) ⇒ Object



34
35
36
37
38
39
40
41
42
# File 'lib/i18n/tasks/command/commands/tree.rb', line 34

def tree_filter(opts = {})
  pattern = arg_or_pos! :pattern, opts
  forest  = forest_pos_or_stdin! opts
  unless pattern.blank?
    pattern_re = i18n.compile_key_pattern(pattern)
    forest     = forest.select_keys { |full_key, _node| full_key =~ pattern_re }
  end
  print_forest forest, opts
end

#tree_merge(opts = {}) ⇒ Object



25
26
27
# File 'lib/i18n/tasks/command/commands/tree.rb', line 25

def tree_merge(opts = {})
  print_forest merge_forests_stdin_and_pos!(opts), opts
end

#tree_mv(opt = {}) ⇒ Object



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

def tree_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 = forest_pos_or_stdin!(opt)
  forest.mv_key!(compile_key_pattern(from_pattern), to_pattern, root: !opt[:'all-locales'])
  print_forest forest, opt
end

#tree_set_value(opt = {}) ⇒ Object



79
80
81
82
83
84
85
86
87
# File 'lib/i18n/tasks/command/commands/tree.rb', line 79

def tree_set_value(opt = {})
  value       = arg_or_pos! :value, opt
  forest      = forest_pos_or_stdin!(opt)
  key_pattern = opt[:pattern]
  fail CommandError, 'pass value (-v, --value)' if value.blank?

  forest.set_each_value!(value, key_pattern)
  print_forest forest, opt
end

#tree_subtract(opt = {}) ⇒ Object



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

def tree_subtract(opt = {})
  forests = forests_stdin_and_pos! opt, 2
  forest  = forests.reduce(:subtract_by_key) || empty_forest
  print_forest forest, opt
end

#tree_translate(opts = {}) ⇒ Object



15
16
17
18
# File 'lib/i18n/tasks/command/commands/tree.rb', line 15

def tree_translate(opts = {})
  forest = forest_pos_or_stdin!(opts)
  print_forest i18n.translate_forest(forest, from: opts[:from], backend: opts[:backend].to_sym), opts
end