Class: OpenapiContracts::Doc::FileParser

Inherits:
Object
  • Object
show all
Defined in:
lib/openapi_contracts/doc/file_parser.rb

Defined Under Namespace

Classes: Result

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rootfile, pathname) ⇒ FileParser

Returns a new instance of FileParser.



17
18
19
20
21
# File 'lib/openapi_contracts/doc/file_parser.rb', line 17

def initialize(rootfile, pathname)
  @root = rootfile.parent
  @rootfile = rootfile
  @pathname = pathname.relative? ? @root.join(pathname) : pathname
end

Class Method Details

.parse(rootfile, pathname) ⇒ Object



13
14
15
# File 'lib/openapi_contracts/doc/file_parser.rb', line 13

def self.parse(rootfile, pathname)
  new(rootfile, pathname).call
end

Instance Method Details

#callObject



23
24
25
26
27
# File 'lib/openapi_contracts/doc/file_parser.rb', line 23

def call
  schema = YAML.safe_load(File.read(@pathname))
  schema = transform_hash(schema)
  Result.new(schema, @pathname.relative_path_from(@root).sub_ext(''))
end