class Raml::Parser

@private

@private

Public Class Methods

parse(data, file_dir=Dir.getwd) click to toggle source
# File lib/raml/parser.rb, line 7
def parse(data, file_dir=Dir.getwd)
  register_include_tag
  
  data = YAML.load data
  expand_includes data, file_dir

  Root.new data
end

Private Class Methods

expand_includes(val, cwd) click to toggle source
# File lib/raml/parser.rb, line 22
def expand_includes(val, cwd)
  case val
  when Hash
    val.merge!(val, &expand_includes_transform_hash(cwd))
  when Array
    val.map!(&expand_includes_transform_array(cwd))
  end
end
expand_includes_transform(val, cwd) click to toggle source
# File lib/raml/parser.rb, line 43
def expand_includes_transform(val, cwd)
  child_wd = cwd

  if val.is_a? Raml::Parser::Include
    child_wd = expand_includes_working_dir cwd, val.path
    val = val.content cwd
  end

  expand_includes val, child_wd

  val
end
expand_includes_transform_array(cwd) click to toggle source
# File lib/raml/parser.rb, line 31
def expand_includes_transform_array(cwd)
  proc do |arg|
    expand_includes_transform(arg, cwd)
  end
end
expand_includes_transform_hash(cwd) click to toggle source
# File lib/raml/parser.rb, line 37
def expand_includes_transform_hash(cwd)
  proc do |arg1, arg2|
    expand_includes_transform(arg2, cwd)
  end
end
expand_includes_working_dir(current_wd, include_pathname) click to toggle source
# File lib/raml/parser.rb, line 56
def expand_includes_working_dir(current_wd, include_pathname)
  include_path = File.dirname include_pathname
  if include_path.start_with? '/'
    include_path
  else
    "#{current_wd}/#{include_path}"
  end
end
register_include_tag() click to toggle source
# File lib/raml/parser.rb, line 18
def register_include_tag
  YAML.add_tag '!include', Raml::Parser::Include
end