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.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +80 -0
- data/.gitignore +44 -37
- data/CHANGELOG.md +106 -101
- data/CONFIG.markdown +67 -67
- data/Gemfile +3 -3
- data/MIT-LICENSE +19 -19
- data/README.markdown +726 -726
- data/Rakefile +17 -17
- data/gemfiles/rails7.1.gemfile +11 -0
- data/gemfiles/{rails5.gemfile → rails7.2.gemfile} +7 -7
- data/gemfiles/{rails6.0.gemfile → rails8.0.gemfile} +7 -8
- data/gemfiles/{rails6.1.gemfile → rails8.1.gemfile} +7 -8
- data/geokit-rails.gemspec +34 -34
- data/lib/generators/geokit_rails/install_generator.rb +13 -13
- data/lib/generators/templates/geokit_config.rb +100 -100
- data/lib/geokit-rails/acts_as_mappable/class_methods.rb +299 -297
- data/lib/geokit-rails/acts_as_mappable/glue.rb +54 -54
- data/lib/geokit-rails/acts_as_mappable.rb +78 -78
- data/lib/geokit-rails/adapters/abstract.rb +30 -30
- data/lib/geokit-rails/adapters/mysql.rb +21 -21
- data/lib/geokit-rails/adapters/mysql2.rb +8 -8
- data/lib/geokit-rails/adapters/mysql2spatial.rb +8 -8
- data/lib/geokit-rails/adapters/oracleenhanced.rb +32 -32
- data/lib/geokit-rails/adapters/postgresql.rb +21 -21
- data/lib/geokit-rails/adapters/sqlite.rb +53 -53
- data/lib/geokit-rails/adapters/sqlserver.rb +45 -45
- data/lib/geokit-rails/distance_collection.rb +8 -8
- data/lib/geokit-rails/geocoder_control.rb +19 -19
- data/lib/geokit-rails/ip_geocode_lookup.rb +44 -45
- data/lib/geokit-rails/railtie.rb +37 -37
- data/lib/geokit-rails/version.rb +3 -3
- data/lib/geokit-rails.rb +11 -11
- data/test/acts_as_mappable_test.rb +486 -478
- data/test/adapter_resolution_test.rb +46 -0
- data/test/boot.rb +40 -32
- data/test/database.yml +31 -28
- data/test/distance_collection_test.rb +41 -41
- data/test/dummy/Rakefile +6 -6
- data/test/dummy/app/assets/stylesheets/application.css +1 -1
- data/test/dummy/app/channels/application_cable/channel.rb +4 -4
- data/test/dummy/app/channels/application_cable/connection.rb +4 -4
- data/test/dummy/app/controllers/application_controller.rb +3 -3
- data/test/dummy/app/controllers/location_aware_controller.rb +42 -42
- data/test/dummy/app/helpers/application_helper.rb +2 -2
- data/test/dummy/app/jobs/application_job.rb +7 -7
- data/test/dummy/app/mailers/application_mailer.rb +4 -4
- data/test/dummy/app/models/application_record.rb +3 -3
- data/test/dummy/app/views/layouts/application.html.erb +15 -15
- data/test/dummy/app/views/layouts/mailer.html.erb +13 -13
- data/test/dummy/app/views/layouts/mailer.text.erb +1 -1
- data/test/dummy/bin/rails +4 -4
- data/test/dummy/bin/rake +4 -4
- data/test/dummy/bin/setup +33 -33
- data/test/dummy/config/application.rb +22 -22
- data/test/dummy/config/boot.rb +5 -5
- data/test/dummy/config/cable.yml +10 -10
- data/test/dummy/config/database.yml +25 -25
- data/test/dummy/config/environment.rb +5 -5
- data/test/dummy/config/environments/development.rb +68 -68
- data/test/dummy/config/environments/production.rb +87 -87
- data/test/dummy/config/environments/test.rb +60 -60
- data/test/dummy/config/initializers/content_security_policy.rb +25 -25
- data/test/dummy/config/initializers/filter_parameter_logging.rb +8 -8
- data/test/dummy/config/initializers/inflections.rb +16 -16
- data/test/dummy/config/initializers/permissions_policy.rb +11 -11
- data/test/dummy/config/locales/en.yml +33 -33
- data/test/dummy/config/puma.rb +43 -43
- data/test/dummy/config/routes.rb +6 -6
- data/test/dummy/config/storage.yml +34 -34
- data/test/dummy/config.ru +6 -6
- data/test/dummy/public/404.html +67 -67
- data/test/dummy/public/422.html +67 -67
- data/test/dummy/public/500.html +66 -66
- data/test/fixtures/companies.yml +9 -9
- data/test/fixtures/custom_locations.yml +61 -61
- data/test/fixtures/locations.yml +61 -61
- data/test/fixtures/mock_addresses.yml +16 -16
- data/test/fixtures/mock_families.yml +2 -2
- data/test/fixtures/mock_houses.yml +8 -8
- data/test/fixtures/mock_organizations.yml +4 -4
- data/test/fixtures/mock_people.yml +4 -4
- data/test/ip_geocode_lookup_test.rb +52 -48
- data/test/models/company.rb +2 -2
- data/test/models/custom_location.rb +11 -11
- data/test/models/location.rb +3 -3
- data/test/models/mock_address.rb +3 -3
- data/test/models/mock_family.rb +4 -4
- data/test/models/mock_house.rb +2 -2
- data/test/models/mock_organization.rb +5 -5
- data/test/models/mock_person.rb +6 -6
- data/test/models/store.rb +2 -2
- data/test/schema.rb +61 -61
- data/test/tasks.rake +37 -37
- data/test/test_helper.rb +83 -73
- metadata +13 -15
- data/.travis.yml +0 -55
- data/gemfiles/rails3.gemfile +0 -8
- 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 '
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
#
|
|
6
|
-
#
|
|
7
|
-
#
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
#
|
|
22
|
-
#
|
|
23
|
-
#
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
session[:geo_location]
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
#
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
location
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
#
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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
|
data/lib/geokit-rails/railtie.rb
CHANGED
|
@@ -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
|
data/lib/geokit-rails/version.rb
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
module GeokitRails
|
|
2
|
-
VERSION = "2.5.
|
|
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'
|