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
17
# File 'lib/raml/parser.rb', line 12

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

Class Method Details

.parse(yaml) ⇒ Object



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

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

.parse_file(path) ⇒ Object



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

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

Instance Method Details

#parse(yaml) ⇒ Object



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

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

#parse_file(path) ⇒ Object



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

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