Module: FlatFile::JSON

Defined in:
lib/flat_file/json.rb

Class Method Summary collapse

Class Method Details

.from_file(file) ⇒ Hash, ActiveSupport::HashWithIndifferentAccess

Return a hash parsed from a given JSON file.

Parameters:

  • file (String)

Returns:

  • (Hash, ActiveSupport::HashWithIndifferentAccess)


10
11
12
13
14
15
16
# File 'lib/flat_file/json.rb', line 10

def self.from_file(file)
  data = ::JSON.parse(File.read(file))
  if defined?(ActiveSupport::HashWithIndifferentAccess)
    return data&.with_indifferent_access || data
  end
  return data
end