class Raml::Parser::Resource

Constants

BASIC_ATTRIBUTES
HTTP_METHODS

Attributes

attributes[RW]
parent_node[RW]
resource[RW]
trait_names[RW]

Public Class Methods

new(parent) click to toggle source
# File lib/raml/parser/resource.rb, line 21
def initialize(parent)
  @parent = parent
end

Public Instance Methods

parse(parent_node, uri_partial, attributes) click to toggle source
# File lib/raml/parser/resource.rb, line 25
def parse(parent_node, uri_partial, attributes)
  @parent_node = parent_node
  @resource = Raml::Resource.new(@parent_node, uri_partial)
  @attributes = prepare_attributes(attributes)
  apply_resource_type
  parse_attributes
  resource
end

Private Instance Methods

apply_resource_type() click to toggle source
# File lib/raml/parser/resource.rb, line 56
def apply_resource_type
  name = attributes['type']
  if name and !resource_types[name].nil?
    resource_attributes = prepare_attributes(resource_types[name])
    @attributes.delete('type')
    @attributes = resource_attributes.deep_merge(attributes)
  end
end
parse_attributes() click to toggle source
# File lib/raml/parser/resource.rb, line 36
def parse_attributes
  attributes.each do |key, value|
    key = underscore(key)
    case key
    when /^\//
      resource.resources << Raml::Parser::Resource.new(self).parse(resource, key, value)
    when *HTTP_METHODS
      resource.http_methods << Raml::Parser::Method.new(self).parse(key, value)
    when *BASIC_ATTRIBUTES
      resource.send("#{key}=", value)
    when 'is'
      @trait_names = value
    when 'uri_parameters'
      @uri_parameters = value
    else
      raise UnknownAttributeError.new "Unknown resource key: #{key}"
    end
  end if attributes
end