Class: Avm::Files::Formatter::Formats::Json

Inherits:
GenericPlain show all
Defined in:
lib/avm/files/formatter/formats/json.rb

Constant Summary collapse

VALID_BASENAMES =
%w[*.json].freeze
VALID_TYPES =
[].freeze

Instance Method Summary collapse

Methods inherited from GenericPlain

#internal_apply, #string_apply

Methods inherited from Base

#apply, #match?, #name, #valid_basenames, #valid_types

Instance Method Details

#file_apply(file) ⇒ Object



13
14
15
# File 'lib/avm/files/formatter/formats/json.rb', line 13

def file_apply(file)
  ::File.write(file, ::JSON.pretty_generate(::JSON.parse(::File.read(file))))
end

#json_file?(file) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
20
21
22
# File 'lib/avm/files/formatter/formats/json.rb', line 17

def json_file?(file)
  ::JSON.parse(::File.read(file))
  true
rescue JSON::ParserError
  false
end