Class: HttpRouter::Node::Path
- Inherits:
-
HttpRouter::Node
- Object
- HttpRouter::Node
- HttpRouter::Node::Path
- Defined in:
- lib/http_router/node/path.rb
Instance Attribute Summary collapse
-
#dynamic ⇒ Object
(also: #dynamic?)
readonly
Returns the value of attribute dynamic.
-
#original_path ⇒ Object
readonly
Returns the value of attribute original_path.
-
#param_names ⇒ Object
readonly
Returns the value of attribute param_names.
-
#route ⇒ Object
readonly
Returns the value of attribute route.
Attributes inherited from HttpRouter::Node
Instance Method Summary collapse
- #hashify_params(params) ⇒ Object
-
#initialize(router, parent, route, path, param_names = []) ⇒ Path
constructor
A new instance of Path.
- #inspect_label ⇒ Object
- #to_code ⇒ Object
- #url(args, options) ⇒ Object
- #usable?(other) ⇒ Boolean
Methods inherited from HttpRouter::Node
#add_arbitrary, #add_destination, #add_free_match, #add_glob, #add_glob_regexp, #add_lookup, #add_match, #add_request, #add_spanning_match, #add_variable, #depth, #inspect, #inspect_matchers_body
Constructor Details
#initialize(router, parent, route, path, param_names = []) ⇒ Path
Returns a new instance of Path.
6 7 8 9 10 11 12 |
# File 'lib/http_router/node/path.rb', line 6 def initialize(router, parent, route, path, param_names = []) @route, @original_path, @param_names, @dynamic = route, path, param_names, !param_names.empty? raise AmbiguousVariableException, "You have duplicate variable name present: #{param_names.join(', ')}" if param_names.uniq.size != param_names.size Util.add_path_generation(self, route, @original_path) if @original_path.respond_to?(:split) super router, parent root.uncompile end |
Instance Attribute Details
#dynamic ⇒ Object (readonly) Also known as: dynamic?
Returns the value of attribute dynamic.
4 5 6 |
# File 'lib/http_router/node/path.rb', line 4 def dynamic @dynamic end |
#original_path ⇒ Object (readonly)
Returns the value of attribute original_path.
4 5 6 |
# File 'lib/http_router/node/path.rb', line 4 def original_path @original_path end |
#param_names ⇒ Object (readonly)
Returns the value of attribute param_names.
4 5 6 |
# File 'lib/http_router/node/path.rb', line 4 def param_names @param_names end |
#route ⇒ Object (readonly)
Returns the value of attribute route.
4 5 6 |
# File 'lib/http_router/node/path.rb', line 4 def route @route end |
Instance Method Details
#hashify_params(params) ⇒ Object
14 15 16 |
# File 'lib/http_router/node/path.rb', line 14 def hashify_params(params) @dynamic && params ? Hash[param_names.zip(params)] : {} end |
#inspect_label ⇒ Object
56 57 58 |
# File 'lib/http_router/node/path.rb', line 56 def inspect_label "Path: #{original_path.inspect} for route #{route.named || 'unnamed route'} to #{route.dest.inspect}" end |
#to_code ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/http_router/node/path.rb', line 25 def to_code path_ivar = inject_root_ivar(self) "#{"if request.path_finished?" unless route.match_partially?} catch(:pass) do #{"if request.path.size == 1 && request.path.first == '' && (request.rack_request.head? || request.rack_request.get?) && request.rack_request.path_info[-1] == ?/ response = ::Rack::Response.new response.redirect(request.rack_request.path_info[0, request.rack_request.path_info.size - 1], 302) throw :success, response.finish end" if router.redirect_trailing_slash?} #{"if request.path.empty?#{" or (request.path.size == 1 and request.path.first == '')" if router.ignore_trailing_slash?}" unless route.match_partially?} if request.perform_call env = request.rack_request.dup.env env['router.request'] = request env['router.params'] ||= {} #{"env['router.params'].merge!(Hash[#{param_names.inspect}.zip(request.params)])" if dynamic?} @router.rewrite#{"_partial" if route.match_partially?}_path_info(env, request) response = @router.process_destination_path(#{path_ivar}, env) router.pass_on_response(response) ? throw(:pass) : throw(:success, response) else throw :success, Response.new(request, #{path_ivar}) end #{"end" unless route.match_partially?} end #{"end" unless route.match_partially?}" end |
#url(args, options) ⇒ Object
18 19 20 21 22 23 |
# File 'lib/http_router/node/path.rb', line 18 def url(args, ) if path = raw_url(args, ) raise TooManyParametersException unless args.empty? [URI.escape(path), ] end end |
#usable?(other) ⇒ Boolean
52 53 54 |
# File 'lib/http_router/node/path.rb', line 52 def usable?(other) other == self end |