Class: Rango::Route
Included Modules
Rango::HttpExceptions
Attributes
Instance Attributes
response | [RW] | public |
router returns callable object . |
---|
Public Visibility
Public Instance Method Summary
#call(request) |
So we can returns responses directly from route. |
---|---|
#default(params) |
default(page: 1). |
#find_strategy(request) | |
#get_strategy(request) | |
#include(*args) | |
#match?(uri) | |
#redirect(url, options = Hash.new) | |
#to(*args, &block) |
TODO: full const get to(Rango. |
Public Instance Method Details
call
public
call(request)
So we can returns responses directly from route
[View source]
59 60 61 62 63 64 65 |
# File 'lib/rango/router/route.rb', line 59 def call(request) if self.response self.response.call(request) else self.get_strategy(request).run end end |
default
public
default(params)
default(page: 1)
[View source]
91 92 93 |
# File 'lib/rango/router/route.rb', line 91 def default(params) self.default_params = params end |
find_strategy
public
find_strategy(request)
[View source]
81 82 83 84 85 86 87 |
# File 'lib/rango/router/route.rb', line 81 def find_strategy(request) return self.strategy if self.strategy Router.strategies.find do |strategy| params = self.default_params strategy.new(request, params, *self.arguments, &self.block).match? end end |
get_strategy
public
get_strategy(request)
[View source]
68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/rango/router/route.rb', line 68 def get_strategy(request) strategy = self.find_strategy(request) raise(AnyStrategyMatched) unless strategy params = self.default_params.merge(self.params) strategy.new(request, params, *self.arguments, self.block) rescue Exception => exception # FIXME: move it on better place Project.logger.exception(exception) Project.logger.debug("strategy: #{strategy.inspect}") Project.logger.debug("route: #{self.inspect}") raise Error500.new(exception, self.params) end |
include
public
include(*args)
[View source]
44 45 46 |
# File 'lib/rango/router/route.rb', line 44 def include(*args) return self end |
match?
public
match?(uri)
[View source]
96 97 98 99 100 101 102 |
# File 'lib/rango/router/route.rb', line 96 def match?(uri) data = uri.match(@match_pattern) unless data.nil? data.names.each { |argument| self.params[argument.to_sym] = data[argument] } end return data end |
redirect
public
redirect(url, options = Hash.new)
[View source]
51 52 53 54 55 56 |
# File 'lib/rango/router/route.rb', line 51 def redirect(url, = Hash.new) self.response = lambda do |request| headers = {"Location" => url} Rack::Response.new(String.new, 302, headers).finish end end |
to
public
to(*args, &block)
TODO: full const get to(Rango.logger.method(:debug))
> Rango.logger.debug(request, *args)
to(“Post#show”, “blog/views”)
> Post.new(request).show(*args)
[View source]
36 37 38 39 40 |
# File 'lib/rango/router/route.rb', line 36 def to(*args, &block) self.arguments = args self.block = block return self end |