geokit-rails 2.3.2 → 2.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (110) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +80 -0
  3. data/.gitignore +44 -37
  4. data/CHANGELOG.md +106 -96
  5. data/CONFIG.markdown +67 -67
  6. data/Gemfile +3 -3
  7. data/MIT-LICENSE +19 -19
  8. data/README.markdown +726 -726
  9. data/Rakefile +17 -17
  10. data/gemfiles/rails7.1.gemfile +11 -0
  11. data/gemfiles/{rails3.gemfile → rails7.2.gemfile} +7 -7
  12. data/gemfiles/{rails4.gemfile → rails8.0.gemfile} +7 -8
  13. data/gemfiles/{rails5.gemfile → rails8.1.gemfile} +7 -8
  14. data/geokit-rails.gemspec +34 -33
  15. data/lib/generators/geokit_rails/install_generator.rb +13 -13
  16. data/lib/generators/templates/geokit_config.rb +100 -100
  17. data/lib/geokit-rails/acts_as_mappable/class_methods.rb +299 -0
  18. data/lib/geokit-rails/acts_as_mappable/glue.rb +54 -0
  19. data/lib/geokit-rails/acts_as_mappable.rb +78 -425
  20. data/lib/geokit-rails/adapters/abstract.rb +30 -30
  21. data/lib/geokit-rails/adapters/mysql.rb +21 -21
  22. data/lib/geokit-rails/adapters/mysql2.rb +8 -8
  23. data/lib/geokit-rails/adapters/mysql2spatial.rb +8 -8
  24. data/lib/geokit-rails/adapters/oracleenhanced.rb +32 -32
  25. data/lib/geokit-rails/adapters/postgresql.rb +21 -21
  26. data/lib/geokit-rails/adapters/sqlite.rb +53 -53
  27. data/lib/geokit-rails/adapters/sqlserver.rb +45 -45
  28. data/lib/geokit-rails/{core_extensions.rb → distance_collection.rb} +8 -8
  29. data/lib/geokit-rails/geocoder_control.rb +19 -19
  30. data/lib/geokit-rails/ip_geocode_lookup.rb +44 -48
  31. data/lib/geokit-rails/railtie.rb +37 -37
  32. data/lib/geokit-rails/version.rb +3 -3
  33. data/lib/geokit-rails.rb +11 -9
  34. data/test/acts_as_mappable_test.rb +486 -478
  35. data/test/adapter_resolution_test.rb +46 -0
  36. data/test/boot.rb +40 -32
  37. data/test/database.yml +31 -28
  38. data/test/distance_collection_test.rb +42 -0
  39. data/test/dummy/Rakefile +6 -0
  40. data/test/dummy/app/assets/images/.keep +0 -0
  41. data/test/dummy/app/assets/stylesheets/application.css +1 -0
  42. data/test/dummy/app/channels/application_cable/channel.rb +4 -0
  43. data/test/dummy/app/channels/application_cable/connection.rb +4 -0
  44. data/test/dummy/app/controllers/application_controller.rb +3 -0
  45. data/test/dummy/app/controllers/concerns/.keep +0 -0
  46. data/test/dummy/app/controllers/location_aware_controller.rb +43 -0
  47. data/test/dummy/app/helpers/application_helper.rb +2 -0
  48. data/test/dummy/app/jobs/application_job.rb +7 -0
  49. data/test/dummy/app/mailers/application_mailer.rb +4 -0
  50. data/test/dummy/app/models/application_record.rb +3 -0
  51. data/test/dummy/app/models/concerns/.keep +0 -0
  52. data/test/dummy/app/views/layouts/application.html.erb +15 -0
  53. data/test/dummy/app/views/layouts/mailer.html.erb +13 -0
  54. data/test/dummy/app/views/layouts/mailer.text.erb +1 -0
  55. data/test/dummy/bin/rails +4 -0
  56. data/test/dummy/bin/rake +4 -0
  57. data/test/dummy/bin/setup +33 -0
  58. data/test/dummy/config/application.rb +22 -0
  59. data/test/dummy/config/boot.rb +5 -0
  60. data/test/dummy/config/cable.yml +10 -0
  61. data/test/dummy/config/database.yml +25 -0
  62. data/test/dummy/config/environment.rb +5 -0
  63. data/test/dummy/config/environments/development.rb +68 -0
  64. data/test/dummy/config/environments/production.rb +87 -0
  65. data/test/dummy/config/environments/test.rb +60 -0
  66. data/test/dummy/config/initializers/content_security_policy.rb +25 -0
  67. data/test/dummy/config/initializers/filter_parameter_logging.rb +8 -0
  68. data/test/dummy/config/initializers/inflections.rb +16 -0
  69. data/test/dummy/config/initializers/permissions_policy.rb +11 -0
  70. data/test/dummy/config/locales/en.yml +33 -0
  71. data/test/dummy/config/puma.rb +43 -0
  72. data/test/dummy/config/routes.rb +6 -0
  73. data/test/dummy/config/storage.yml +34 -0
  74. data/test/dummy/config.ru +6 -0
  75. data/test/dummy/lib/assets/.keep +0 -0
  76. data/test/dummy/log/.keep +0 -0
  77. data/test/dummy/public/404.html +67 -0
  78. data/test/dummy/public/422.html +67 -0
  79. data/test/dummy/public/500.html +66 -0
  80. data/test/dummy/public/apple-touch-icon-precomposed.png +0 -0
  81. data/test/dummy/public/apple-touch-icon.png +0 -0
  82. data/test/dummy/public/favicon.ico +0 -0
  83. data/test/dummy/storage/.keep +0 -0
  84. data/test/dummy/tmp/.keep +0 -0
  85. data/test/dummy/tmp/pids/.keep +0 -0
  86. data/test/dummy/tmp/storage/.keep +0 -0
  87. data/test/fixtures/companies.yml +9 -9
  88. data/test/fixtures/custom_locations.yml +61 -61
  89. data/test/fixtures/locations.yml +61 -61
  90. data/test/fixtures/mock_addresses.yml +16 -16
  91. data/test/fixtures/mock_families.yml +2 -2
  92. data/test/fixtures/mock_houses.yml +8 -8
  93. data/test/fixtures/mock_organizations.yml +4 -4
  94. data/test/fixtures/mock_people.yml +4 -4
  95. data/test/ip_geocode_lookup_test.rb +53 -0
  96. data/test/models/company.rb +2 -2
  97. data/test/models/custom_location.rb +11 -11
  98. data/test/models/location.rb +3 -3
  99. data/test/models/mock_address.rb +3 -3
  100. data/test/models/mock_family.rb +4 -4
  101. data/test/models/mock_house.rb +2 -2
  102. data/test/models/mock_organization.rb +5 -5
  103. data/test/models/mock_person.rb +6 -6
  104. data/test/models/store.rb +2 -2
  105. data/test/schema.rb +61 -61
  106. data/test/tasks.rake +37 -37
  107. data/test/test_helper.rb +83 -56
  108. metadata +137 -37
  109. data/.travis.yml +0 -29
  110. data/test/ip_geocode_lookup_test.disabled.rb +0 -82
@@ -1,32 +1,32 @@
1
- module Geokit
2
- module Adapters
3
- class OracleEnhanced < Abstract
4
- TO_DEGREES = Math::PI / 180
5
- def sphere_distance_sql(lat, lng, multiplier)
6
- %{
7
- (
8
- ACOS(
9
- COS(#{lat}) * COS(#{lng}) *
10
- COS(#{TO_DEGREES} * #{qualified_lat_column_name}) *
11
- COS(#{TO_DEGREES} * #{qualified_lng_column_name}) +
12
- COS(#{lat}) * SIN(#{lng}) *
13
- COS(#{TO_DEGREES} * #{qualified_lat_column_name}) *
14
- SIN(#{TO_DEGREES} * #{qualified_lng_column_name}) +
15
- SIN(#{lat}) *
16
- SIN(#{TO_DEGREES} * #{qualified_lat_column_name})
17
- ) *
18
- #{multiplier})
19
- }
20
- end
21
-
22
- def flat_distance_sql(origin, lat_degree_units, lng_degree_units)
23
- %{
24
- SQRT(
25
- POWER(#{lat_degree_units}*(#{origin.lat}-#{qualified_lat_column_name}), 2)
26
- POWER(#{lng_degree_units}*(#{origin.lng}-#{qualified_lng_column_name}), 2)
27
- )
28
- }
29
- end
30
- end
31
- end
32
- end
1
+ module Geokit
2
+ module Adapters
3
+ class OracleEnhanced < Abstract
4
+ TO_DEGREES = Math::PI / 180
5
+ def sphere_distance_sql(lat, lng, multiplier)
6
+ %{
7
+ (
8
+ ACOS(
9
+ COS(#{lat}) * COS(#{lng}) *
10
+ COS(#{TO_DEGREES} * #{qualified_lat_column_name}) *
11
+ COS(#{TO_DEGREES} * #{qualified_lng_column_name}) +
12
+ COS(#{lat}) * SIN(#{lng}) *
13
+ COS(#{TO_DEGREES} * #{qualified_lat_column_name}) *
14
+ SIN(#{TO_DEGREES} * #{qualified_lng_column_name}) +
15
+ SIN(#{lat}) *
16
+ SIN(#{TO_DEGREES} * #{qualified_lat_column_name})
17
+ ) *
18
+ #{multiplier})
19
+ }
20
+ end
21
+
22
+ def flat_distance_sql(origin, lat_degree_units, lng_degree_units)
23
+ %{
24
+ SQRT(
25
+ POWER(#{lat_degree_units}*(#{origin.lat}-#{qualified_lat_column_name}), 2)
26
+ POWER(#{lng_degree_units}*(#{origin.lng}-#{qualified_lng_column_name}), 2)
27
+ )
28
+ }
29
+ end
30
+ end
31
+ end
32
+ end
@@ -1,22 +1,22 @@
1
- module Geokit
2
- module Adapters
3
- class PostgreSQL < Abstract
4
-
5
- def sphere_distance_sql(lat, lng, multiplier)
6
- %|
7
- (ACOS(least(1,COS(#{lat})*COS(#{lng})*COS(RADIANS(#{qualified_lat_column_name}))*COS(RADIANS(#{qualified_lng_column_name}))+
8
- COS(#{lat})*SIN(#{lng})*COS(RADIANS(#{qualified_lat_column_name}))*SIN(RADIANS(#{qualified_lng_column_name}))+
9
- SIN(#{lat})*SIN(RADIANS(#{qualified_lat_column_name}))))*#{multiplier})
10
- |
11
- end
12
-
13
- def flat_distance_sql(origin, lat_degree_units, lng_degree_units)
14
- %|
15
- SQRT(POW(#{lat_degree_units}*(#{origin.lat}-#{qualified_lat_column_name}),2)+
16
- POW(#{lng_degree_units}*(#{origin.lng}-#{qualified_lng_column_name}),2))
17
- |
18
- end
19
-
20
- end
21
- end
1
+ module Geokit
2
+ module Adapters
3
+ class PostgreSQL < Abstract
4
+
5
+ def sphere_distance_sql(lat, lng, multiplier)
6
+ %|
7
+ (ACOS(least(1,COS(#{lat})*COS(#{lng})*COS(RADIANS(#{qualified_lat_column_name}))*COS(RADIANS(#{qualified_lng_column_name}))+
8
+ COS(#{lat})*SIN(#{lng})*COS(RADIANS(#{qualified_lat_column_name}))*SIN(RADIANS(#{qualified_lng_column_name}))+
9
+ SIN(#{lat})*SIN(RADIANS(#{qualified_lat_column_name}))))*#{multiplier})
10
+ |
11
+ end
12
+
13
+ def flat_distance_sql(origin, lat_degree_units, lng_degree_units)
14
+ %|
15
+ SQRT(POW(#{lat_degree_units}*(#{origin.lat}-#{qualified_lat_column_name}),2)+
16
+ POW(#{lng_degree_units}*(#{origin.lng}-#{qualified_lng_column_name}),2))
17
+ |
18
+ end
19
+
20
+ end
21
+ end
22
22
  end
@@ -1,53 +1,53 @@
1
- module Geokit
2
- module Adapters
3
- class SQLite < Abstract
4
-
5
- def self.add_numeric(name)
6
- @@connection.create_function name, 1, SQLite3::Constants::TextRep::ANY do |func, *args|
7
- func.result = yield(*args)
8
- end
9
- end
10
-
11
- def self.add_math(name)
12
- add_numeric name do |*n|
13
- Math.send name, *n
14
- end
15
- end
16
-
17
- class << self
18
- def load(klass)
19
- @@connection = klass.connection.raw_connection
20
- # Define the functions needed
21
- add_math 'sqrt'
22
- add_math 'cos'
23
- add_math 'acos'
24
- add_math 'sin'
25
-
26
- add_numeric('pow') { |n, m| n**m }
27
- add_numeric('radians') { |n| n * Math::PI / 180 }
28
- add_numeric('least') { |*args| args.min }
29
- end
30
- end
31
-
32
- def sphere_distance_sql(lat, lng, multiplier)
33
- %|
34
- (CASE WHEN #{qualified_lat_column_name} IS NULL OR #{qualified_lng_column_name} IS NULL THEN NULL ELSE
35
- (ACOS(least(1,COS(#{lat})*COS(#{lng})*COS(RADIANS(#{qualified_lat_column_name}))*COS(RADIANS(#{qualified_lng_column_name}))+
36
- COS(#{lat})*SIN(#{lng})*COS(RADIANS(#{qualified_lat_column_name}))*SIN(RADIANS(#{qualified_lng_column_name}))+
37
- SIN(#{lat})*SIN(RADIANS(#{qualified_lat_column_name}))))*#{multiplier})
38
- END)
39
- |
40
- end
41
-
42
- def flat_distance_sql(origin, lat_degree_units, lng_degree_units)
43
- %|
44
- (CASE WHEN #{qualified_lat_column_name} IS NULL OR #{qualified_lng_column_name} IS NULL THEN NULL ELSE
45
- SQRT(POW(#{lat_degree_units}*(#{origin.lat}-#{qualified_lat_column_name}),2)+
46
- POW(#{lng_degree_units}*(#{origin.lng}-#{qualified_lng_column_name}),2))
47
- END)
48
- |
49
- end
50
-
51
- end
52
- end
53
- end
1
+ module Geokit
2
+ module Adapters
3
+ class SQLite < Abstract
4
+
5
+ def self.add_numeric(name)
6
+ @@connection.create_function name, 1, SQLite3::Constants::TextRep::ANY do |func, *args|
7
+ func.result = yield(*args)
8
+ end
9
+ end
10
+
11
+ def self.add_math(name)
12
+ add_numeric name do |*n|
13
+ Math.send name, *n
14
+ end
15
+ end
16
+
17
+ class << self
18
+ def load(klass)
19
+ @@connection = klass.connection.raw_connection
20
+ # Define the functions needed
21
+ add_math 'sqrt'
22
+ add_math 'cos'
23
+ add_math 'acos'
24
+ add_math 'sin'
25
+
26
+ add_numeric('pow') { |n, m| n**m }
27
+ add_numeric('radians') { |n| n * Math::PI / 180 }
28
+ add_numeric('least') { |*args| args.min }
29
+ end
30
+ end
31
+
32
+ def sphere_distance_sql(lat, lng, multiplier)
33
+ %|
34
+ (CASE WHEN #{qualified_lat_column_name} IS NULL OR #{qualified_lng_column_name} IS NULL THEN NULL ELSE
35
+ (ACOS(least(1,COS(#{lat})*COS(#{lng})*COS(RADIANS(#{qualified_lat_column_name}))*COS(RADIANS(#{qualified_lng_column_name}))+
36
+ COS(#{lat})*SIN(#{lng})*COS(RADIANS(#{qualified_lat_column_name}))*SIN(RADIANS(#{qualified_lng_column_name}))+
37
+ SIN(#{lat})*SIN(RADIANS(#{qualified_lat_column_name}))))*#{multiplier})
38
+ END)
39
+ |
40
+ end
41
+
42
+ def flat_distance_sql(origin, lat_degree_units, lng_degree_units)
43
+ %|
44
+ (CASE WHEN #{qualified_lat_column_name} IS NULL OR #{qualified_lng_column_name} IS NULL THEN NULL ELSE
45
+ SQRT(POW(#{lat_degree_units}*(#{origin.lat}-#{qualified_lat_column_name}),2)+
46
+ POW(#{lng_degree_units}*(#{origin.lng}-#{qualified_lng_column_name}),2))
47
+ END)
48
+ |
49
+ end
50
+
51
+ end
52
+ end
53
+ end
@@ -1,45 +1,45 @@
1
- module Geokit
2
- module Adapters
3
- class SQLServer < Abstract
4
-
5
- class << self
6
-
7
- def load(klass)
8
- klass.transaction do
9
- klass.connection.execute <<-EOS
10
- if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[geokit_least]') and xtype in (N'FN', N'IF', N'TF'))
11
- drop function [dbo].[geokit_least]
12
- EOS
13
-
14
- klass.connection.execute <<-EOS
15
- CREATE FUNCTION [dbo].geokit_least (@value1 float,@value2 float) RETURNS float AS BEGIN
16
- return (SELECT CASE WHEN @value1 < @value2 THEN @value1 ELSE @value2 END) END
17
- EOS
18
- end
19
- self.loaded = true
20
- end
21
-
22
- end
23
-
24
- def initialize(*args)
25
- super(*args)
26
- end
27
-
28
- def sphere_distance_sql(lat, lng, multiplier)
29
- %|
30
- (ACOS([dbo].geokit_least(1,COS(#{lat})*COS(#{lng})*COS(RADIANS(#{qualified_lat_column_name}))*COS(RADIANS(#{qualified_lng_column_name}))+
31
- COS(#{lat})*SIN(#{lng})*COS(RADIANS(#{qualified_lat_column_name}))*SIN(RADIANS(#{qualified_lng_column_name}))+
32
- SIN(#{lat})*SIN(RADIANS(#{qualified_lat_column_name}))))*#{multiplier})
33
- |
34
- end
35
-
36
- def flat_distance_sql(origin, lat_degree_units, lng_degree_units)
37
- %|
38
- SQRT(POWER(#{lat_degree_units}*(#{origin.lat}-#{qualified_lat_column_name}),2)+
39
- POWER(#{lng_degree_units}*(#{origin.lng}-#{qualified_lng_column_name}),2))
40
- |
41
- end
42
-
43
- end
44
- end
45
- end
1
+ module Geokit
2
+ module Adapters
3
+ class SQLServer < Abstract
4
+
5
+ class << self
6
+
7
+ def load(klass)
8
+ klass.transaction do
9
+ klass.connection.execute <<-EOS
10
+ if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[geokit_least]') and xtype in (N'FN', N'IF', N'TF'))
11
+ drop function [dbo].[geokit_least]
12
+ EOS
13
+
14
+ klass.connection.execute <<-EOS
15
+ CREATE FUNCTION [dbo].geokit_least (@value1 float,@value2 float) RETURNS float AS BEGIN
16
+ return (SELECT CASE WHEN @value1 < @value2 THEN @value1 ELSE @value2 END) END
17
+ EOS
18
+ end
19
+ self.loaded = true
20
+ end
21
+
22
+ end
23
+
24
+ def initialize(*args)
25
+ super(*args)
26
+ end
27
+
28
+ def sphere_distance_sql(lat, lng, multiplier)
29
+ %|
30
+ (ACOS([dbo].geokit_least(1,COS(#{lat})*COS(#{lng})*COS(RADIANS(#{qualified_lat_column_name}))*COS(RADIANS(#{qualified_lng_column_name}))+
31
+ COS(#{lat})*SIN(#{lng})*COS(RADIANS(#{qualified_lat_column_name}))*SIN(RADIANS(#{qualified_lng_column_name}))+
32
+ SIN(#{lat})*SIN(RADIANS(#{qualified_lat_column_name}))))*#{multiplier})
33
+ |
34
+ end
35
+
36
+ def flat_distance_sql(origin, lat_degree_units, lng_degree_units)
37
+ %|
38
+ SQRT(POWER(#{lat_degree_units}*(#{origin.lat}-#{qualified_lat_column_name}),2)+
39
+ POWER(#{lng_degree_units}*(#{origin.lng}-#{qualified_lng_column_name}),2))
40
+ |
41
+ end
42
+
43
+ end
44
+ end
45
+ end
@@ -1,8 +1,8 @@
1
- class DistanceCollection < Array
2
- def set_distance_from(origin, opts={})
3
- distance_attribute_name = opts.delete(:distance_attribute_name) || 'distance'
4
- klass = first.class
5
- klass.send(:attr_accessor, distance_attribute_name) if !klass.respond_to?("#{distance_attribute_name}=")
6
- each{|e| e.send("#{distance_attribute_name}=", e.distance_to(origin,opts)) }
7
- end
8
- end
1
+ class DistanceCollection < Array
2
+ def set_distance_from(origin, opts={})
3
+ distance_attribute_name = opts.delete(:distance_attribute_name) || 'distance'
4
+ klass = first.class
5
+ klass.send(:attr_accessor, distance_attribute_name) if !klass.respond_to?("#{distance_attribute_name}=")
6
+ each{|e| e.send("#{distance_attribute_name}=", e.distance_to(origin,opts)) }
7
+ end
8
+ end
@@ -1,19 +1,19 @@
1
- require 'active_support/concern'
2
-
3
- module Geokit
4
- module GeocoderControl
5
- extend ActiveSupport::Concern
6
-
7
- included do
8
- if respond_to? :before_action
9
- send :before_action, :set_geokit_domain
10
- elsif respond_to? :before_filter
11
- send :before_filter, :set_geokit_domain
12
- end
13
- end
14
-
15
- def set_geokit_domain
16
- Geokit::Geocoders::domain = request.domain
17
- end
18
- end
19
- end
1
+ require 'active_support/concern'
2
+
3
+ module Geokit
4
+ module GeocoderControl
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+ if respond_to? :before_action
9
+ send :before_action, :set_geokit_domain
10
+ elsif respond_to? :before_filter
11
+ send :before_filter, :set_geokit_domain
12
+ end
13
+ end
14
+
15
+ def set_geokit_domain
16
+ Geokit::Geocoders::domain = request.domain
17
+ end
18
+ end
19
+ end
@@ -1,48 +1,44 @@
1
- require 'yaml'
2
- require 'active_support/concern'
3
-
4
- module Geokit
5
- # Contains a class method geocode_ip_address which can be used to enable automatic geocoding
6
- # for request IP addresses. The geocoded information is stored in a cookie and in the
7
- # session to minimize web service calls. The point of the helper is to enable location-based
8
- # websites to have a best-guess for new visitors.
9
- module IpGeocodeLookup
10
- extend ActiveSupport::Concern
11
-
12
- # Class method to mix into active record.
13
- module ClassMethods # :nodoc:
14
- def geocode_ip_address(filter_options = {})
15
- if respond_to? :before_action
16
- before_action :store_ip_location, filter_options
17
- else
18
- before_filter :store_ip_location, filter_options
19
- end
20
- end
21
- end
22
-
23
- private
24
-
25
- # Places the IP address' geocode location into the session if it
26
- # can be found. Otherwise, looks for a geo location cookie and
27
- # uses that value. The last resort is to call the web service to
28
- # get the value.
29
- def store_ip_location
30
- session[:geo_location] ||= retrieve_location_from_cookie_or_service
31
- cookies[:geo_location] = { :value => session[:geo_location].to_yaml, :expires => 30.days.from_now } if session[:geo_location]
32
- end
33
-
34
- # Uses the stored location value from the cookie if it exists. If
35
- # no cookie exists, calls out to the web service to get the location.
36
- def retrieve_location_from_cookie_or_service
37
- return GeoLoc.new(YAML.load(cookies[:geo_location])) if cookies[:geo_location]
38
- location = Geocoders::MultiGeocoder.geocode(get_ip_address)
39
- return location.success ? location : nil
40
- end
41
-
42
- # Returns the real ip address, though this could be the localhost ip
43
- # address. No special handling here anymore.
44
- def get_ip_address
45
- request.remote_ip
46
- end
47
- end
48
- end
1
+ require 'active_support/concern'
2
+
3
+ module Geokit
4
+ # Contains a class method geocode_ip_address which can be used to enable automatic geocoding
5
+ # for request IP addresses. The geocoded information is stored in a cookie and in the
6
+ # session to minimize web service calls. The point of the helper is to enable location-based
7
+ # websites to have a best-guess for new visitors.
8
+ module IpGeocodeLookup
9
+ extend ActiveSupport::Concern
10
+
11
+ # Class method to mix into active record.
12
+ module ClassMethods # :nodoc:
13
+ def geocode_ip_address(filter_options = {})
14
+ before_action :store_ip_location, filter_options
15
+ end
16
+ end
17
+
18
+ private
19
+
20
+ # Places the IP address' geocode location into the session if it
21
+ # can be found. Otherwise, looks for a geo location cookie and
22
+ # uses that value. The last resort is to call the web service to
23
+ # get the value.
24
+ def store_ip_location
25
+ session[:geo_location] ||= retrieve_location_from_cookie_or_service
26
+ cookies[:geo_location] = { :value => session[:geo_location].to_json, :expires => 30.days.from_now } if session[:geo_location]
27
+ end
28
+
29
+ # Uses the stored location value from the cookie if it exists. If
30
+ # no cookie exists, calls out to the web service to get the location.
31
+ def retrieve_location_from_cookie_or_service
32
+ # return GeoLoc.new(YAML.load(cookies[:geo_location])) if cookies[:geo_location]
33
+ return GeoLoc.new(JSON.parse(cookies[:geo_location])) if cookies[:geo_location]
34
+ location = Geocoders::MultiGeocoder.geocode(get_ip_address)
35
+ return location.success ? location : nil
36
+ end
37
+
38
+ # Returns the real ip address, though this could be the localhost ip
39
+ # address. No special handling here anymore.
40
+ def get_ip_address
41
+ request.remote_ip
42
+ end
43
+ end
44
+ end
@@ -1,37 +1,37 @@
1
- require 'rails'
2
-
3
- module Geokit
4
-
5
- class Railtie < ::Rails::Railtie
6
-
7
- config.geokit = ActiveSupport::OrderedOptions.new
8
- config.geokit.geocoders = ActiveSupport::OrderedOptions.new
9
-
10
- initializer 'geokit-rails.insert_into_active_record' do
11
- ActiveSupport.on_load :active_record do
12
- ActiveRecord::Base.send(:include, Geokit::ActsAsMappable::Glue)
13
- Geokit::Geocoders.logger = ActiveRecord::Base.logger
14
- end
15
- end
16
-
17
- initializer 'geokit-rails.insert_into_action_controller' do
18
- ActiveSupport.on_load :action_controller do
19
- ActionController::Base.send(:include, Geokit::GeocoderControl)
20
- ActionController::Base.send(:include, Geokit::IpGeocodeLookup)
21
- end
22
- end
23
-
24
- config.after_initialize do |app|
25
- options = app.config.geokit
26
- geocoders_options = options.delete(:geocoders)
27
-
28
- options.each do |k,v|
29
- Geokit::send("#{k}=", v)
30
- end
31
- geocoders_options.each do |k,v|
32
- Geokit::Geocoders::send("#{k}=", v)
33
- end
34
- end
35
- end
36
-
37
- end
1
+ require 'rails'
2
+
3
+ module Geokit
4
+
5
+ class Railtie < ::Rails::Railtie
6
+
7
+ config.geokit = ActiveSupport::OrderedOptions.new
8
+ config.geokit.geocoders = ActiveSupport::OrderedOptions.new
9
+
10
+ initializer 'geokit-rails.insert_into_active_record' do
11
+ ActiveSupport.on_load :active_record do
12
+ ActiveRecord::Base.send(:include, Geokit::ActsAsMappable::Glue)
13
+ Geokit::Geocoders.logger = ActiveRecord::Base.logger
14
+ end
15
+ end
16
+
17
+ initializer 'geokit-rails.insert_into_action_controller' do
18
+ ActiveSupport.on_load :action_controller do
19
+ ActionController::Base.send(:include, Geokit::GeocoderControl)
20
+ ActionController::Base.send(:include, Geokit::IpGeocodeLookup)
21
+ end
22
+ end
23
+
24
+ config.after_initialize do |app|
25
+ options = app.config.geokit
26
+ geocoders_options = options.delete(:geocoders)
27
+
28
+ options.each do |k,v|
29
+ Geokit::send("#{k}=", v)
30
+ end
31
+ geocoders_options.each do |k,v|
32
+ Geokit::Geocoders::send("#{k}=", v)
33
+ end
34
+ end
35
+ end
36
+
37
+ end
@@ -1,3 +1,3 @@
1
- module GeokitRails
2
- VERSION = "2.3.2"
3
- end
1
+ module GeokitRails
2
+ VERSION = "2.5.1"
3
+ end
data/lib/geokit-rails.rb CHANGED
@@ -1,9 +1,11 @@
1
- require 'geokit'
2
-
3
- require 'geokit-rails/railtie'
4
- require 'geokit-rails/core_extensions'
5
-
6
- require 'geokit-rails/adapters/abstract'
7
- require 'geokit-rails/acts_as_mappable'
8
- require 'geokit-rails/geocoder_control'
9
- require 'geokit-rails/ip_geocode_lookup'
1
+ require 'geokit'
2
+
3
+ require 'geokit-rails/railtie'
4
+ require 'geokit-rails/distance_collection'
5
+
6
+ require 'geokit-rails/adapters/abstract'
7
+ require 'geokit-rails/acts_as_mappable/glue'
8
+ require 'geokit-rails/acts_as_mappable/class_methods'
9
+ require 'geokit-rails/acts_as_mappable'
10
+ require 'geokit-rails/geocoder_control'
11
+ require 'geokit-rails/ip_geocode_lookup'