From 525be6733d52931d1c0784b7933a9c3eafd63460 Mon Sep 17 00:00:00 2001 From: Sean Collins Date: Sun, 8 May 2016 12:00:46 -0600 Subject: [PATCH] Fix many ruby warnings --- http_router.gemspec | 1 + lib/http_router.rb | 5 ++++- lib/http_router/generator.rb | 10 ++++++---- lib/http_router/node/abstract_request_node.rb | 4 ++-- lib/http_router/request.rb | 6 ++++-- lib/http_router/route.rb | 6 +++++- lib/http_router/route_helper.rb | 4 ++-- 7 files changed, 24 insertions(+), 12 deletions(-) diff --git a/http_router.gemspec b/http_router.gemspec index 0dc6d00..02f137e 100644 --- a/http_router.gemspec +++ b/http_router.gemspec @@ -22,6 +22,7 @@ Gem::Specification.new do |s| # dependencies s.add_runtime_dependency 'rack', '>= 1.0.0' s.add_runtime_dependency 'url_mount', '~> 0.2.1' + s.add_runtime_dependency 'addressable', '~> 2.4' s.add_development_dependency 'minitest', '~> 2.0.0' s.add_development_dependency 'code_stats' s.add_development_dependency 'rake', '~> 0.8.7' diff --git a/lib/http_router.rb b/lib/http_router.rb index a7a378c..14f687d 100644 --- a/lib/http_router.rb +++ b/lib/http_router.rb @@ -47,6 +47,7 @@ def initialize(*args, &blk) @ignore_trailing_slash = options && options.key?(:ignore_trailing_slash) ? options[:ignore_trailing_slash] : true @redirect_trailing_slash = options && options.key?(:redirect_trailing_slash) ? options[:redirect_trailing_slash] : false @route_class = Route + @compiled = false reset! instance_eval(&blk) if blk end @@ -118,7 +119,9 @@ def route_class # Adds a path that only responds to the request method +GET+. # # Returns the route object. - def get(path, opts = {}, &app); add_with_request_method(path, [:get, :head], opts, &app); end + def get(path, opts = {}, &app) + add_with_request_method(path, [:get, :head], opts, &app) + end # Performs recoginition without actually calling the application and returns an array of all # matching routes or nil if no match was found. diff --git a/lib/http_router/generator.rb b/lib/http_router/generator.rb index 51d6d8c..f6f74e8 100644 --- a/lib/http_router/generator.rb +++ b/lib/http_router/generator.rb @@ -1,3 +1,5 @@ +require 'addressable/uri' + class HttpRouter class Generator SCHEME_PORTS = {'http' => 80, 'https' => 443} @@ -36,13 +38,13 @@ def initialize(route, path, validation_regex = nil) instance_eval <<-EOT, __FILE__, __LINE__ + 1 def generate(args, options) generated_path = \"#{code}\" - #{validation_regex.inspect}.match(generated_path) ? URI.escape(generated_path) : nil + #{validation_regex.inspect}.match(generated_path) ? Addressable::URI.escape(generated_path) : nil end EOT else instance_eval <<-EOT, __FILE__, __LINE__ + 1 def generate(args, options) - URI.escape(\"#{code}\") + Addressable::URI.escape(\"#{code}\") end EOT end @@ -55,7 +57,7 @@ def initialize(route, paths) @router = @route.router @route.generator = self @path_generators = @paths.map do |p| - generator = PathGenerator.new(route, p.is_a?(String) ? p : route.path_for_generation, p.is_a?(Regexp) ? p : nil) + PathGenerator.new(route, p.is_a?(String) ? p : route.path_for_generation, p.is_a?(Regexp) ? p : nil) end end @@ -147,4 +149,4 @@ def append_querystring(uri, params) uri end end -end \ No newline at end of file +end diff --git a/lib/http_router/node/abstract_request_node.rb b/lib/http_router/node/abstract_request_node.rb index f022850..8afeb3b 100644 --- a/lib/http_router/node/abstract_request_node.rb +++ b/lib/http_router/node/abstract_request_node.rb @@ -26,6 +26,6 @@ def to_code def inspect_label "#{self.class.name.split("::").last} #{tests.inspect} (#{@matchers.size} matchers)" end - end + end end -end \ No newline at end of file +end diff --git a/lib/http_router/request.rb b/lib/http_router/request.rb index f5c9d64..d3fcada 100644 --- a/lib/http_router/request.rb +++ b/lib/http_router/request.rb @@ -1,3 +1,5 @@ +require 'addressable/uri' + class HttpRouter class Request attr_accessor :path, :params, :rack_request, :extra_env, :continue, :passed_with, :called @@ -7,7 +9,7 @@ class Request def initialize(path, rack_request) @rack_request = rack_request - @path = URI.unescape(path).split(/\//) + @path = Addressable::URI.unescape(path).split(/\//) @path.shift if @path.first == '' @path.push('') if path[-1] == ?/ @extra_env = {} @@ -27,4 +29,4 @@ def path_finished? @path.size == 0 or @path.size == 1 && @path.first == '' end end -end \ No newline at end of file +end diff --git a/lib/http_router/route.rb b/lib/http_router/route.rb index 9c19d02..0918370 100644 --- a/lib/http_router/route.rb +++ b/lib/http_router/route.rb @@ -3,13 +3,17 @@ class HttpRouter class Route # The list of HTTP request methods supported by HttpRouter. - VALID_HTTP_VERBS = %w{GET POST PUT DELETE HEAD OPTIONS TRACE PATCH OPTIONS LINK UNLINK} + VALID_HTTP_VERBS = %w{GET POST PUT DELETE HEAD OPTIONS TRACE PATCH LINK UNLINK} VALID_HTTP_VERBS_WITHOUT_GET = VALID_HTTP_VERBS - %w{GET} attr_reader :default_values, :other_hosts, :paths, :request_methods, :name attr_accessor :match_partially, :router, :host, :user_agent, :ignore_trailing_slash, :path_for_generation, :path_validation_regex, :generator, :scheme, :original_path, :dest + def initialize + @match_with = nil + end + def create_clone(new_router) r = clone r.dest = (begin; dest.clone; rescue; dest; end) diff --git a/lib/http_router/route_helper.rb b/lib/http_router/route_helper.rb index eccf942..1240e87 100644 --- a/lib/http_router/route_helper.rb +++ b/lib/http_router/route_helper.rb @@ -108,10 +108,10 @@ def static(root) @match_partially = true if File.directory?(root) to File.directory?(root) ? ::Rack::File.new(root) : - proc {|env| + proc {|env| env['PATH_INFO'] = File.basename(root) ::Rack::File.new(File.dirname(root)).call(env) } end end -end \ No newline at end of file +end