Class: Raml::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/raml/parser.rb,
lib/raml/parser/body.rb,
lib/raml/parser/root.rb,
lib/raml/parser/util.rb,
lib/raml/parser/method.rb,
lib/raml/parser/resource.rb,
lib/raml/parser/response.rb,
lib/raml/parser/documentation.rb,
lib/raml/parser/query_parameter.rb

Defined Under Namespace

Modules: Util Classes: Body, Documentation, Method, QueryParameter, Resource, Response, Root

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeParser

Returns a new instance of Parser.



12
13
14
15
16
# File 'lib/raml/parser.rb', line 12

def initialize
  Psych.add_domain_type 'include', 'include' do |_, value|
    File.read(value)
  end
end

Class Method Details

.parse(yaml) ⇒ Object



34
35
36
# File 'lib/raml/parser.rb', line 34

def self.parse(yaml)
  self.new.parse(yaml)
end

.parse_file(path) ⇒ Object



38
39
40
# File 'lib/raml/parser.rb', line 38

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

Instance Method Details

#parse(yaml) ⇒ Object



18
19
20
21
# File 'lib/raml/parser.rb', line 18

def parse(yaml)
  raml = YAML.load(yaml)
  Raml::Parser::Root.new.parse(raml)
end

#parse_file(path) ⇒ Object



23
24
25
26
27
28
29
30
31
32
# File 'lib/raml/parser.rb', line 23

def parse_file(path)
  # Change directories so that relative file !includes work properly
  wd = Dir.pwd
  Dir.chdir File.dirname(path)

  raml = parse File.read(File.basename(path))

  Dir.chdir wd
  raml
end