Module: YARD::Handlers::Sinatra::AbstractRouteHandler

Included in:
Legacy::RouteHandler, RouteHandler
Defined in:
lib/yard/sinatra.rb

Overview

Logic both handlers have in common.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.error_handlersObject



44
45
46
# File 'lib/yard/sinatra.rb', line 44

def self.error_handlers
  @error_handlers ||= []
end

.routesObject



40
41
42
# File 'lib/yard/sinatra.rb', line 40

def self.routes
  @routes ||= []
end

Instance Method Details

#processObject



48
49
50
51
52
53
54
55
56
57
# File 'lib/yard/sinatra.rb', line 48

def process
  case http_verb
  when 'NOT_FOUND'
    register_error_handler(http_verb)
  else
    path = http_path
    path = $1 if path =~ /^"(.*)"$/
    register_route(http_verb, path)
  end
end

#register_error_handler(verb, doc = nil) {|error_handler| ... } ⇒ Object

Yields:

  • (error_handler)


79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/yard/sinatra.rb', line 79

def register_error_handler(verb, doc = nil)
  error_handler = register CodeObjects::RouteObject.new(namespace, verb, :instance) do |o|
    o.visibility = "public"
    o.source     = statement.source
    o.signature  = verb
    o.explicit   = true
    o.scope      = scope
    o.docstring  = statement.comments
    o.http_verb  = verb
    o.real_name  = verb
    o.add_file(parser.file, statement.line)
  end
  AbstractRouteHandler.error_handlers << error_handler
  yield(error_handler) if block_given?
end

#register_route(verb, path, doc = nil) {|route| ... } ⇒ Object

Yields:

  • (route)


59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/yard/sinatra.rb', line 59

def register_route(verb, path, doc = nil)
  # HACK: Removing some illegal letters.
  method_name = "" << verb << "_" << path.gsub(/[^\w_]/, "_")
  real_name   = "" << verb << " " << path
  route = register CodeObjects::RouteObject.new(namespace, method_name, :instance) do |o|
    o.visibility = "public"
    o.source     = statement.source
    o.signature  = real_name
    o.explicit   = true
    o.scope      = scope
    o.docstring  = statement.comments
    o.http_verb  = verb
    o.http_path  = path
    o.real_name  = real_name
    o.add_file(parser.file, statement.line)
  end
  AbstractRouteHandler.routes << route
  yield(route) if block_given?
end