Class: OpenapiValidator::FileLoader

Inherits:
Object
  • Object
show all
Defined in:
lib/openapi_validator/file_loader.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.call(path) ⇒ Hash

Returns parsed file.

Parameters:

  • path (String)

    path to file

Returns:

  • (Hash)

    parsed file



8
9
10
# File 'lib/openapi_validator/file_loader.rb', line 8

def self.call(path)
  new(path).call
end

Instance Method Details

#callHash

Returns parsed file.

Returns:

  • (Hash)

    parsed file



13
14
15
16
17
18
19
20
21
22
# File 'lib/openapi_validator/file_loader.rb', line 13

def call
  case File.extname(path)
  when ".yml", ".yaml"
    YAML.load_file(path)
  when ".json"
    JSON.parse(File.read(path))
  else
    raise "Can't parse #{path}. It should be json or yaml file.", Error
  end
end