Class: PhraseAppUpdater::LocaleFile::JSONFile

Inherits:
PhraseAppUpdater::LocaleFile show all
Defined in:
lib/phraseapp_updater/locale_file/json_file.rb

Constant Summary collapse

EXTENSION =
"json"
PHRASEAPP_TYPE =
"nested_json"

Instance Attribute Summary

Attributes inherited from PhraseAppUpdater::LocaleFile

#content, #locale_name, #parsed_content

Class Method Summary collapse

Methods inherited from PhraseAppUpdater::LocaleFile

class_for_file_format, #filename, from_file_content, from_hash, load_directory, load_file, #to_s

Class Method Details

.dump(hash) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/phraseapp_updater/locale_file/json_file.rb', line 22

def dump(hash)
  # Add indentation for better diffs
  json = Oj.dump(hash, indent: '  ', space:  ' ', object_nl: "\n", array_nl: "\n", mode: :strict)
  # Oj omits end of file newline unless using the integer form of :indent
  json << "\n"
  json
end

.extensionObject



30
31
32
# File 'lib/phraseapp_updater/locale_file/json_file.rb', line 30

def extension
  EXTENSION
end

.load(content) ⇒ Object



16
17
18
19
20
# File 'lib/phraseapp_updater/locale_file/json_file.rb', line 16

def load(content)
  Oj.load(content)
rescue Oj::ParseError => e
  raise ArgumentError.new("Provided content was not valid JSON: #{e}")
end

.phraseapp_typeObject



34
35
36
# File 'lib/phraseapp_updater/locale_file/json_file.rb', line 34

def phraseapp_type
  PHRASEAPP_TYPE
end