Module: I18n::Tasks::Data::FileFormats::ClassMethods

Defined in:
lib/i18n/tasks/data/file_formats.rb

Instance Method Summary collapse

Instance Method Details

#adapter_by_name(name) ⇒ Object



86
87
88
89
90
91
92
93
94
# File 'lib/i18n/tasks/data/file_formats.rb', line 86

def adapter_by_name(name)
  name = name.to_s
  @fn_patterns.detect do |(adapter_name, _pattern, _adapter)|
    adapter_name.to_s == name
  end.try(:last) || fail(
    CommandError,
    "Adapter with name #{name.inspect} not found. Registered adapters: #{@fn_patterns.inspect}"
  )
end

#adapter_name_for_path(path) ⇒ Object



74
75
76
77
78
79
80
# File 'lib/i18n/tasks/data/file_formats.rb', line 74

def adapter_name_for_path(path)
  @fn_patterns.detect do |(_name, pattern, _adapter)|
    ::File.fnmatch(pattern, path)
  end.try(:first) || fail(
    CommandError, "Adapter not found for #{path}. Registered adapters: #{@fn_patterns.inspect}"
  )
end

#adapter_namesObject



82
83
84
# File 'lib/i18n/tasks/data/file_formats.rb', line 82

def adapter_names
  @fn_patterns.map(&:first)
end

#register_adapter(name, pattern, adapter) ⇒ Object

Parameters:

  • pattern (String)

    File.fnmatch pattern

  • adapter (responds to parse(string)-)

    hash and dump(hash)->string]



70
71
72
# File 'lib/i18n/tasks/data/file_formats.rb', line 70

def register_adapter(name, pattern, adapter)
  (@fn_patterns ||= []) << [name, pattern, adapter]
end