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, #name, #parsed_content

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from PhraseAppUpdater::LocaleFile

class_for_file_format, #initialize, #name_with_extension, #to_s

Constructor Details

This class inherits a constructor from PhraseAppUpdater::LocaleFile

Class Method Details

.from_hash(name, hash) ⇒ Object



14
15
16
# File 'lib/phraseapp_updater/locale_file/json_file.rb', line 14

def self.from_hash(name, hash)
  new(name, MultiJson.dump(hash))
end

Instance Method Details

#format_content!Object



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

def format_content!
  # Add indentation for better diffs
  @content = MultiJson.dump(MultiJson.load(@content), pretty: true)
end

#parse(content) ⇒ Object



18
19
20
21
22
# File 'lib/phraseapp_updater/locale_file/json_file.rb', line 18

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