Class: RDoc::Parser::Sinatra

Inherits:
Ruby
  • Object
show all
Defined in:
lib/rdoc/parser/sinatra.rb

Overview

An augmented Ruby parser for Sinatra projects.

In addition to normal Ruby doc, documentation is also extracted for route definitions.

Constant Summary collapse

HTTP_VERBS =
%w[GET HEAD POST PUT PATCH DELETE OPTIONS]
HTTP_ERRORS =
{"NOT_FOUND" => 404, "ERROR" => 500}

Instance Method Summary collapse

Constructor Details

#initialize(top_level, file_name, content, options, stats) ⇒ Sinatra

New parser, adds a top-level Application Routes.



55
56
57
58
59
60
61
62
# File 'lib/rdoc/parser/sinatra.rb', line 55

def initialize(top_level, file_name, content, options, stats)
  super

  # Tuck away our little special module
  @routes = @top_level.add_module RDoc::SinatraRoutes, "Application Routes"

  @current_route = nil
end

Instance Method Details

#parse_meta_method(container, single, token, comment) ⇒ Object

Override normal meta-method parsing to handle Sinatra routes and errors.



67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/rdoc/parser/sinatra.rb', line 67

def parse_meta_method(container, single, token, comment)
  name = token.name.upcase

  case name
  when *HTTP_VERBS
    r = parse_route_definition token
    r.comment = comment
  when "NOT_FOUND", "ERROR"
    r = parse_error_definition token
    r.comment = comment
  else
    super
  end
end