class OpenapiValidator::FileLoader

Attributes

path[R]

Public Class Methods

call(path) click to toggle source

@param [String] path path to file @return [Hash] parsed file

# File lib/openapi_validator/file_loader.rb, line 8
def self.call(path)
  new(path).call
end
new(path) click to toggle source

@param [String] path path to file

# File lib/openapi_validator/file_loader.rb, line 29
def initialize(path)
  @path = path
end

Public Instance Methods

call() click to toggle source

@return [Hash] parsed file

# 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