Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fix warnings #608

Merged
merged 6 commits into from

2 participants

@exviva

Fix several warnings and one bug (using respond_to? instead of method_defined?)

@alexreisner
Owner

This is interesting, but we need to fix the test failures. (Why is the use of respond_to? a bug? It provides stronger protection against overwriting something useful than method_defined? which will not catch functionality implemented with, for example, method_missing.)

@exviva

@alexreisner respond_to? will almost always return false in this scope (of the Test class, not an instance of Test). We want to check if an instance of Test responds to, say, location, and not the Test class object.

I'll look into the failed build now.

@exviva

Test failures are actually exposing the bug I've mentioned - the method address was always being redefined because if respond_to?(:address) was always false.

The solution I came up with involves removing the method before redefining it - similar to how activesupport is doing it.

@alexreisner
Owner

OK, thanks for the fix. This is great! Makes me think we should work towards the elimination of all warnings.

@alexreisner alexreisner merged commit 3c0859c into alexreisner:master
@exviva

Thanks for merging! I've run my project's specs with this version of geocoder, and these were the warnings that I've caught. Probably running geocoder's specs with -w would reveal even more warnings.

@alexreisner
Owner

Yep, plenty more are thrown by the test suite. Thanks for getting the process started!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
5 lib/geocoder/cache.rb
@@ -49,7 +49,8 @@ def expire(url)
private # ----------------------------------------------------------------
- attr_reader :prefix, :store
+ def prefix; @prefix; end
+ def store; @store; end
##
# Cache key for a given URL.
@@ -63,7 +64,7 @@ def key_for(url)
# that have non-nil values.
#
def keys
- store.keys.select{ |k| k.match /^#{prefix}/ and interpret(store[k]) }
+ store.keys.select{ |k| k.match(/^#{prefix}/) and interpret(store[k]) }
end
##
View
3  lib/geocoder/lookups/base.rb
@@ -15,6 +15,9 @@ module Geocoder
module Lookup
class Base
+ def initialize
+ @cache = nil
+ end
##
# Human-readable name of the geocoding API.
View
2  lib/geocoder/lookups/cloudmade.rb
@@ -24,7 +24,7 @@ def results(query)
end
def query_url_params(query)
- params = {
+ {
:query => query.sanitized_text,
:return_location => true,
:return_geometry => false
View
4 lib/geocoder/lookups/maxmind_local.rb
@@ -7,7 +7,7 @@ class MaxmindLocal < Base
def initialize
begin
require 'geoip'
- rescue LoadError => e
+ rescue LoadError
raise 'Could not load geoip dependency. To use MaxMind Local lookup you must add geoip gem to your Gemfile or have it installed in your system.'
end
@@ -38,4 +38,4 @@ def results(query)
result.nil? ? [] : [result.to_hash]
end
end
-end
+end
View
2  lib/geocoder/lookups/yahoo.rb
@@ -50,7 +50,7 @@ def results(query)
# to warning message.
#
def parse_raw_data(raw_data)
- if raw_data.match /^<\?xml/
+ if raw_data.match(/^<\?xml/)
if raw_data.include?("Rate Limit Exceeded")
raise_error(Geocoder::OverQueryLimitError) || warn("Over API query limit.")
elsif raw_data =~ /<yahoo:description>(Please provide valid credentials.*)<\/yahoo:description>/i
View
5 lib/geocoder/models/base.rb
@@ -1,5 +1,3 @@
-require 'geocoder'
-
module Geocoder
##
@@ -29,7 +27,7 @@ def reverse_geocoded_by
private # ----------------------------------------------------------------
def geocoder_init(options)
- unless @geocoder_options
+ unless defined?(@geocoder_options)
@geocoder_options = {}
require "geocoder/stores/#{geocoder_file_name}"
include Geocoder::Store.const_get(geocoder_module_name)
@@ -39,4 +37,3 @@ def geocoder_init(options)
end
end
end
-
View
1  lib/geocoder/railtie.rb
@@ -1,4 +1,3 @@
-require 'geocoder'
require 'geocoder/models/active_record'
module Geocoder
View
2  lib/geocoder/request.rb
@@ -1,5 +1,3 @@
-require 'geocoder'
-
module Geocoder
module Request
View
5 lib/geocoder/results/test.rb
@@ -5,7 +5,10 @@ module Result
class Test < Base
def self.add_result_attribute(attr)
- return if respond_to?(attr.to_sym)
+ begin
+ remove_method(attr) if method_defined?(attr)
+ rescue NameError # method defined on superclass
+ end
define_method(attr) do
@data[attr.to_s] || @data[attr.to_sym]
View
2  lib/geocoder/stores/active_record.rb
@@ -219,7 +219,7 @@ def add_exclude_condition(conditions, exclude)
end
def using_sqlite?
- connection.adapter_name.match /sqlite/i
+ connection.adapter_name.match(/sqlite/i)
end
##
Something went wrong with that request. Please try again.