Object
# File lib/http_router/route.rb, line 7 def initialize(router, path, opts = {}) @router, @original_path, @opts = router, path, opts if @original_path @match_partially = true and path.slice!(-1) if @original_path[/[^\\]\*$/] @original_path[0, 0] = '/' if @original_path[0] != // else @match_partially = true end process_opts end
# File lib/http_router/route.rb, line 74 def add_to_contitions(name, *vals) ((@conditions ||= {})[name] ||= []).concat(vals.flatten) self end
# File lib/http_router/route.rb, line 121 def arbitrary(blk = nil, &blk2) arbitrary_with_continue { |req, params| req.continue[(blk || blk2)[req, params]] } end
# File lib/http_router/route.rb, line 127 def arbitrary_with_continue(blk = nil, &blk2) (@arbitrary ||= []) << (blk || blk2) self end
# File lib/http_router/route.rb, line 32 def as_options {:__matching__ => @matches_with, :__conditions__ => @conditions, :__default_values__ => @default_values, :__name__ => @named, :__partial__ => @partially_match, :__arbitrary__ => @arbitrary} end
# File lib/http_router/route.rb, line 137 def clone(new_router) Route.new(new_router, @original_path.dup, as_options) end
# File lib/http_router/route.rb, line 36 def compiled? !@paths.nil? end
# File lib/http_router/route.rb, line 119 def conenct; request_method('CONNECT'); end
# File lib/http_router/route.rb, line 84 def default(defaults) (@default_values ||= {}).merge!(defaults) self end
# File lib/http_router/route.rb, line 114 def delete; request_method('DELETE'); end
# File lib/http_router/route.rb, line 112 def get; request_method('GET'); end
# File lib/http_router/route.rb, line 115 def head; request_method('HEAD'); end
# File lib/http_router/route.rb, line 62 def host(*host) add_to_contitions(:host, host) end
# File lib/http_router/route.rb, line 79 def matching(matchers) @matches_with.merge!(matchers.is_a?(Array) ? Hash[*matchers] : matchers) self end
# File lib/http_router/route.rb, line 162 def matching_path(params, other_hash = nil) return @paths.first if @paths.size == 1 case params when Array significant_keys = other_hash && significant_variable_names & other_hash.keys @paths.find { |path| path.param_names.size == (significant_keys ? params.size + significant_keys.size : params.size) } when Hash @paths.find { |path| (params && !params.empty? && (path.param_names & params.keys).size == path.param_names.size) || path.param_names.empty? } end end
# File lib/http_router/route.rb, line 51 def name(n) @named = n @router.named_routes[n] << self @router.named_routes[n].sort!{|r1, r2| r2.significant_variable_names.size <=> r1.significant_variable_names.size } self end
# File lib/http_router/route.rb, line 116 def options; request_method('OPTIONS'); end
# File lib/http_router/route.rb, line 40 def partial(match_partially = true) @match_partially = match_partially self end
# File lib/http_router/route.rb, line 117 def patch; request_method('PATCH'); end
# File lib/http_router/route.rb, line 111 def post; request_method('POST'); end
# File lib/http_router/route.rb, line 18 def process_opts @default_values = @opts[:__default_values__] || @opts[:default_values] || {} @arbitrary = @opts[:__arbitrary__] || @opts[:arbitrary] @matches_with = significant_variable_names.include?(:matching) ? @opts : @opts[:__matching__] || @opts[:matching] || {} significant_variable_names.each do |name| @matches_with[name] = @opts[name] if @opts.key?(name) && !@matches_with.key?(name) end @conditions = @opts[:__conditions__] || @opts[:conditions] || {} @match_partially = @opts[:__partial__] if @match_partially.nil? && !@opts[:__partial__].nil? @match_partially = @opts[:partial] if @match_partially.nil? && !@opts[:partial].nil? name(@opts[:__name__] || @opts[:name]) if @opts.key?(:__name__) || @opts.key?(:name) @needed_keys = significant_variable_names - @default_values.keys end
# File lib/http_router/route.rb, line 113 def put; request_method('PUT'); end
Sets the destination of this route to redirect to an arbitrary URL.
# File lib/http_router/route.rb, line 90 def redirect(path, status = 302) raise ArgumentError, "Status has to be an integer between 300 and 399" unless (300..399).include?(status) to { |env| params = env['router.params'] response = ::Rack::Response.new response.redirect(eval(%"#{path}"|), status) response.finish } self end
# File lib/http_router/route.rb, line 58 def request_method(*method) add_to_contitions(:request_method, method) end
# File lib/http_router/route.rb, line 66 def scheme(*scheme) add_to_contitions(:scheme, scheme) end
# File lib/http_router/route.rb, line 158 def significant_variable_names @significant_variable_names ||= @original_path.nil? ? [] : @original_path.scan(/(^|[^\\])[:\*]([a-zA-Z0-9_]+)/).map{|p| p.last.to_sym} end
Sets the destination of this route to serve static files from either a directory or a single file.
# File lib/http_router/route.rb, line 102 def static(root) if File.directory?(root) partial.to ::Rack::File.new(root) else to {|env| env['PATH_INFO'] = File.basename(root); ::Rack::File.new(File.dirname(root)).call(env) } end self end
# File lib/http_router/route.rb, line 45 def to(dest = nil, &dest2) @dest = dest || dest2 add_path_to_tree self end
# File lib/http_router/route.rb, line 173 def to_s "#<HttpRouter:Route #{object_id} @original_path=#{@original_path.inspect} @conditions=#{@conditions.inspect} @arbitrary=#{@arbitrary.inspect}>" end
# File lib/http_router/route.rb, line 118 def trace; request_method('TRACE'); end
# File lib/http_router/route.rb, line 132 def url(*args) result, extra_params = url_with_params(*args) append_querystring(result, extra_params) end
# File lib/http_router/route.rb, line 149 def url_args_processing(args) options = args.last.is_a?(Hash) ? args.pop : nil options = options.nil? ? default_values.dup : default_values.merge(options) if default_values options.delete_if{ |k,v| v.nil? } if options result, params = yield args, options mount_point = router.url_mount && router.url_mount.url(options) mount_point ? [File.join(mount_point, result), params] : [result, params] end
Generated with the Darkfish Rdoc Generator 2.