geokit-rails 2.5.0 → 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 (99) 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 -101
  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/{rails5.gemfile → rails7.2.gemfile} +7 -7
  12. data/gemfiles/{rails6.0.gemfile → rails8.0.gemfile} +7 -8
  13. data/gemfiles/{rails6.1.gemfile → rails8.1.gemfile} +7 -8
  14. data/geokit-rails.gemspec +34 -34
  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 -297
  18. data/lib/geokit-rails/acts_as_mappable/glue.rb +54 -54
  19. data/lib/geokit-rails/acts_as_mappable.rb +78 -78
  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/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 -45
  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 -11
  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 +41 -41
  39. data/test/dummy/Rakefile +6 -6
  40. data/test/dummy/app/assets/stylesheets/application.css +1 -1
  41. data/test/dummy/app/channels/application_cable/channel.rb +4 -4
  42. data/test/dummy/app/channels/application_cable/connection.rb +4 -4
  43. data/test/dummy/app/controllers/application_controller.rb +3 -3
  44. data/test/dummy/app/controllers/location_aware_controller.rb +42 -42
  45. data/test/dummy/app/helpers/application_helper.rb +2 -2
  46. data/test/dummy/app/jobs/application_job.rb +7 -7
  47. data/test/dummy/app/mailers/application_mailer.rb +4 -4
  48. data/test/dummy/app/models/application_record.rb +3 -3
  49. data/test/dummy/app/views/layouts/application.html.erb +15 -15
  50. data/test/dummy/app/views/layouts/mailer.html.erb +13 -13
  51. data/test/dummy/app/views/layouts/mailer.text.erb +1 -1
  52. data/test/dummy/bin/rails +4 -4
  53. data/test/dummy/bin/rake +4 -4
  54. data/test/dummy/bin/setup +33 -33
  55. data/test/dummy/config/application.rb +22 -22
  56. data/test/dummy/config/boot.rb +5 -5
  57. data/test/dummy/config/cable.yml +10 -10
  58. data/test/dummy/config/database.yml +25 -25
  59. data/test/dummy/config/environment.rb +5 -5
  60. data/test/dummy/config/environments/development.rb +68 -68
  61. data/test/dummy/config/environments/production.rb +87 -87
  62. data/test/dummy/config/environments/test.rb +60 -60
  63. data/test/dummy/config/initializers/content_security_policy.rb +25 -25
  64. data/test/dummy/config/initializers/filter_parameter_logging.rb +8 -8
  65. data/test/dummy/config/initializers/inflections.rb +16 -16
  66. data/test/dummy/config/initializers/permissions_policy.rb +11 -11
  67. data/test/dummy/config/locales/en.yml +33 -33
  68. data/test/dummy/config/puma.rb +43 -43
  69. data/test/dummy/config/routes.rb +6 -6
  70. data/test/dummy/config/storage.yml +34 -34
  71. data/test/dummy/config.ru +6 -6
  72. data/test/dummy/public/404.html +67 -67
  73. data/test/dummy/public/422.html +67 -67
  74. data/test/dummy/public/500.html +66 -66
  75. data/test/fixtures/companies.yml +9 -9
  76. data/test/fixtures/custom_locations.yml +61 -61
  77. data/test/fixtures/locations.yml +61 -61
  78. data/test/fixtures/mock_addresses.yml +16 -16
  79. data/test/fixtures/mock_families.yml +2 -2
  80. data/test/fixtures/mock_houses.yml +8 -8
  81. data/test/fixtures/mock_organizations.yml +4 -4
  82. data/test/fixtures/mock_people.yml +4 -4
  83. data/test/ip_geocode_lookup_test.rb +52 -48
  84. data/test/models/company.rb +2 -2
  85. data/test/models/custom_location.rb +11 -11
  86. data/test/models/location.rb +3 -3
  87. data/test/models/mock_address.rb +3 -3
  88. data/test/models/mock_family.rb +4 -4
  89. data/test/models/mock_house.rb +2 -2
  90. data/test/models/mock_organization.rb +5 -5
  91. data/test/models/mock_person.rb +6 -6
  92. data/test/models/store.rb +2 -2
  93. data/test/schema.rb +61 -61
  94. data/test/tasks.rake +37 -37
  95. data/test/test_helper.rb +83 -73
  96. metadata +13 -15
  97. data/.travis.yml +0 -55
  98. data/gemfiles/rails3.gemfile +0 -8
  99. data/gemfiles/rails4.gemfile +0 -8
@@ -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,45 +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
- before_action :store_ip_location, filter_options
16
- end
17
- end
18
-
19
- private
20
-
21
- # Places the IP address' geocode location into the session if it
22
- # can be found. Otherwise, looks for a geo location cookie and
23
- # uses that value. The last resort is to call the web service to
24
- # get the value.
25
- def store_ip_location
26
- session[:geo_location] ||= retrieve_location_from_cookie_or_service
27
- cookies[:geo_location] = { :value => session[:geo_location].to_json, :expires => 30.days.from_now } if session[:geo_location]
28
- end
29
-
30
- # Uses the stored location value from the cookie if it exists. If
31
- # no cookie exists, calls out to the web service to get the location.
32
- def retrieve_location_from_cookie_or_service
33
- # return GeoLoc.new(YAML.load(cookies[:geo_location])) if cookies[:geo_location]
34
- return GeoLoc.new(JSON.parse(cookies[:geo_location])) if cookies[:geo_location]
35
- location = Geocoders::MultiGeocoder.geocode(get_ip_address)
36
- return location.success ? location : nil
37
- end
38
-
39
- # Returns the real ip address, though this could be the localhost ip
40
- # address. No special handling here anymore.
41
- def get_ip_address
42
- request.remote_ip
43
- end
44
- end
45
- 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.5.0"
3
- end
1
+ module GeokitRails
2
+ VERSION = "2.5.1"
3
+ end
data/lib/geokit-rails.rb CHANGED
@@ -1,11 +1,11 @@
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'
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'