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,54 +1,54 @@
1
- module Geokit
2
- module ActsAsMappable
3
-
4
- # Add the +acts_as_mappable+ method into ActiveRecord subclasses
5
- module Glue # :nodoc:
6
- extend ActiveSupport::Concern
7
-
8
- module ClassMethods # :nodoc:
9
- OPTION_SYMBOLS = [ :distance_column_name, :default_units, :default_formula, :lat_column_name, :lng_column_name, :qualified_lat_column_name, :qualified_lng_column_name, :skip_loading ]
10
-
11
- def acts_as_mappable(options = {})
12
- metaclass = (class << self; self; end)
13
-
14
- include Geokit::ActsAsMappable
15
-
16
- cattr_accessor :through
17
- self.through = options[:through]
18
-
19
- if reflection = Geokit::ActsAsMappable.end_of_reflection_chain(self.through, self)
20
- metaclass.instance_eval do
21
- OPTION_SYMBOLS.each do |method_name|
22
- define_method method_name do
23
- reflection.klass.send(method_name)
24
- end
25
- end
26
- end
27
- else
28
- cattr_accessor *OPTION_SYMBOLS
29
-
30
- self.distance_column_name = options[:distance_column_name] || 'distance'
31
- self.default_units = options[:default_units] || Geokit::default_units
32
- self.default_formula = options[:default_formula] || Geokit::default_formula
33
- self.lat_column_name = options[:lat_column_name] || 'lat'
34
- self.lng_column_name = options[:lng_column_name] || 'lng'
35
- self.skip_loading = options[:skip_loading]
36
- self.qualified_lat_column_name = "#{table_name}.#{lat_column_name}"
37
- self.qualified_lng_column_name = "#{table_name}.#{lng_column_name}"
38
-
39
- if options.include?(:auto_geocode) && options[:auto_geocode]
40
- # if the form auto_geocode=>true is used, let the defaults take over by suppling an empty hash
41
- options[:auto_geocode] = {} if options[:auto_geocode] == true
42
- cattr_accessor :auto_geocode_field, :auto_geocode_error_message
43
- self.auto_geocode_field = options[:auto_geocode][:field] || 'address'
44
- self.auto_geocode_error_message = options[:auto_geocode][:error_message] || 'could not locate address'
45
-
46
- # set the actual callback here
47
- before_validation :auto_geocode_address, :on => :create
48
- end
49
- end
50
- end
51
- end
52
- end # Glue
53
- end
54
- end
1
+ module Geokit
2
+ module ActsAsMappable
3
+
4
+ # Add the +acts_as_mappable+ method into ActiveRecord subclasses
5
+ module Glue # :nodoc:
6
+ extend ActiveSupport::Concern
7
+
8
+ module ClassMethods # :nodoc:
9
+ OPTION_SYMBOLS = [ :distance_column_name, :default_units, :default_formula, :lat_column_name, :lng_column_name, :qualified_lat_column_name, :qualified_lng_column_name, :skip_loading ]
10
+
11
+ def acts_as_mappable(options = {})
12
+ metaclass = (class << self; self; end)
13
+
14
+ include Geokit::ActsAsMappable
15
+
16
+ cattr_accessor :through
17
+ self.through = options[:through]
18
+
19
+ if reflection = Geokit::ActsAsMappable.end_of_reflection_chain(self.through, self)
20
+ metaclass.instance_eval do
21
+ OPTION_SYMBOLS.each do |method_name|
22
+ define_method method_name do
23
+ reflection.klass.send(method_name)
24
+ end
25
+ end
26
+ end
27
+ else
28
+ cattr_accessor *OPTION_SYMBOLS
29
+
30
+ self.distance_column_name = options[:distance_column_name] || 'distance'
31
+ self.default_units = options[:default_units] || Geokit::default_units
32
+ self.default_formula = options[:default_formula] || Geokit::default_formula
33
+ self.lat_column_name = options[:lat_column_name] || 'lat'
34
+ self.lng_column_name = options[:lng_column_name] || 'lng'
35
+ self.skip_loading = options[:skip_loading]
36
+ self.qualified_lat_column_name = "#{table_name}.#{lat_column_name}"
37
+ self.qualified_lng_column_name = "#{table_name}.#{lng_column_name}"
38
+
39
+ if options.include?(:auto_geocode) && options[:auto_geocode]
40
+ # if the form auto_geocode=>true is used, let the defaults take over by suppling an empty hash
41
+ options[:auto_geocode] = {} if options[:auto_geocode] == true
42
+ cattr_accessor :auto_geocode_field, :auto_geocode_error_message
43
+ self.auto_geocode_field = options[:auto_geocode][:field] || 'address'
44
+ self.auto_geocode_error_message = options[:auto_geocode][:error_message] || 'could not locate address'
45
+
46
+ # set the actual callback here
47
+ before_validation :auto_geocode_address, :on => :create
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end # Glue
53
+ end
54
+ end
@@ -1,78 +1,78 @@
1
- require 'active_record'
2
- require 'active_support/concern'
3
-
4
- module Geokit
5
- module ActsAsMappable
6
-
7
- class UnsupportedAdapter < StandardError ; end
8
-
9
- #class Relation < ActiveRecord::Relation
10
- # attr_accessor :distance_formula
11
-
12
- # def where(opts, *rest)
13
- # return self if opts.blank?
14
- # relation = clone
15
- # where_values = build_where(opts, rest)
16
- # relation.where_values += substitute_distance_in_values(where_values)
17
- # relation
18
- # end
19
-
20
- # def order(*args)
21
- # return self if args.blank?
22
- # relation = clone
23
- # order_values = args.flatten
24
- # relation.order_values += substitute_distance_in_values(order_values)
25
- # relation
26
- # end
27
-
28
- #private
29
- # def substitute_distance_in_values(values)
30
- # return values unless @distance_formula
31
- # # substitute distance with the actual distance equation
32
- # pattern = Regexp.new("\\b#{@klass.distance_column_name}\\b")
33
- # values.map {|value| value.is_a?(String) ? value.gsub(pattern, @distance_formula) : value }
34
- # end
35
- #end
36
-
37
- extend ActiveSupport::Concern
38
-
39
- included do
40
- include Geokit::Mappable
41
- end
42
-
43
- # this is the callback for auto_geocoding
44
- def auto_geocode_address
45
- address=self.send(auto_geocode_field).to_s
46
- geo=Geokit::Geocoders::MultiGeocoder.geocode(address)
47
-
48
- if geo.success
49
- self.send("#{lat_column_name}=", geo.send(:"#{lat_column_name}"))
50
- self.send("#{lng_column_name}=", geo.send(:"#{lng_column_name}"))
51
- else
52
- errors.add(auto_geocode_field, auto_geocode_error_message)
53
- end
54
-
55
- geo.success
56
- end
57
-
58
- def self.end_of_reflection_chain(through, klass)
59
- while through
60
- reflection = nil
61
- if through.is_a?(Hash)
62
- association, through = through.to_a.first
63
- else
64
- association, through = through, nil
65
- end
66
-
67
- if reflection = klass.reflect_on_association(association)
68
- klass = reflection.klass
69
- else
70
- raise ArgumentError, "You gave #{association} in :through, but I could not find it on #{klass}."
71
- end
72
- end
73
-
74
- reflection
75
- end
76
-
77
- end # ActsAsMappable
78
- end # Geokit
1
+ require 'active_record'
2
+ require 'active_support/concern'
3
+
4
+ module Geokit
5
+ module ActsAsMappable
6
+
7
+ class UnsupportedAdapter < StandardError ; end
8
+
9
+ #class Relation < ActiveRecord::Relation
10
+ # attr_accessor :distance_formula
11
+
12
+ # def where(opts, *rest)
13
+ # return self if opts.blank?
14
+ # relation = clone
15
+ # where_values = build_where(opts, rest)
16
+ # relation.where_values += substitute_distance_in_values(where_values)
17
+ # relation
18
+ # end
19
+
20
+ # def order(*args)
21
+ # return self if args.blank?
22
+ # relation = clone
23
+ # order_values = args.flatten
24
+ # relation.order_values += substitute_distance_in_values(order_values)
25
+ # relation
26
+ # end
27
+
28
+ #private
29
+ # def substitute_distance_in_values(values)
30
+ # return values unless @distance_formula
31
+ # # substitute distance with the actual distance equation
32
+ # pattern = Regexp.new("\\b#{@klass.distance_column_name}\\b")
33
+ # values.map {|value| value.is_a?(String) ? value.gsub(pattern, @distance_formula) : value }
34
+ # end
35
+ #end
36
+
37
+ extend ActiveSupport::Concern
38
+
39
+ included do
40
+ include Geokit::Mappable
41
+ end
42
+
43
+ # this is the callback for auto_geocoding
44
+ def auto_geocode_address
45
+ address=self.send(auto_geocode_field).to_s
46
+ geo=Geokit::Geocoders::MultiGeocoder.geocode(address)
47
+
48
+ if geo.success
49
+ self.send("#{lat_column_name}=", geo.send(:"#{lat_column_name}"))
50
+ self.send("#{lng_column_name}=", geo.send(:"#{lng_column_name}"))
51
+ else
52
+ errors.add(auto_geocode_field, auto_geocode_error_message)
53
+ end
54
+
55
+ geo.success
56
+ end
57
+
58
+ def self.end_of_reflection_chain(through, klass)
59
+ while through
60
+ reflection = nil
61
+ if through.is_a?(Hash)
62
+ association, through = through.to_a.first
63
+ else
64
+ association, through = through, nil
65
+ end
66
+
67
+ if reflection = klass.reflect_on_association(association)
68
+ klass = reflection.klass
69
+ else
70
+ raise ArgumentError, "You gave #{association} in :through, but I could not find it on #{klass}."
71
+ end
72
+ end
73
+
74
+ reflection
75
+ end
76
+
77
+ end # ActsAsMappable
78
+ end # Geokit
@@ -1,31 +1,31 @@
1
- module Geokit
2
- module Adapters
3
- class Abstract
4
- class NotImplementedError < StandardError ; end
5
-
6
- cattr_accessor :loaded
7
-
8
- class << self
9
- def load(klass) ; end
10
- end
11
-
12
- def initialize(klass)
13
- @owner = klass
14
- end
15
-
16
- def method_missing(method, *args, &block)
17
- return @owner.send(method, *args, &block) if @owner.respond_to?(method)
18
- super
19
- end
20
-
21
- def sphere_distance_sql(lat, lng, multiplier)
22
- raise NotImplementedError, '#sphere_distance_sql is not implemented'
23
- end
24
-
25
- def flat_distance_sql(origin, lat_degree_units, lng_degree_units)
26
- raise NotImplementedError, '#flat_distance_sql is not implemented'
27
- end
28
-
29
- end
30
- end
1
+ module Geokit
2
+ module Adapters
3
+ class Abstract
4
+ class NotImplementedError < StandardError ; end
5
+
6
+ cattr_accessor :loaded
7
+
8
+ class << self
9
+ def load(klass) ; end
10
+ end
11
+
12
+ def initialize(klass)
13
+ @owner = klass
14
+ end
15
+
16
+ def method_missing(method, *args, &block)
17
+ return @owner.send(method, *args, &block) if @owner.respond_to?(method)
18
+ super
19
+ end
20
+
21
+ def sphere_distance_sql(lat, lng, multiplier)
22
+ raise NotImplementedError, '#sphere_distance_sql is not implemented'
23
+ end
24
+
25
+ def flat_distance_sql(origin, lat_degree_units, lng_degree_units)
26
+ raise NotImplementedError, '#flat_distance_sql is not implemented'
27
+ end
28
+
29
+ end
30
+ end
31
31
  end
@@ -1,22 +1,22 @@
1
- module Geokit
2
- module Adapters
3
- class MySQL < 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 MySQL < 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,8 +1,8 @@
1
- require 'geokit-rails/adapters/mysql'
2
-
3
- module Geokit
4
- module Adapters
5
- class Mysql2 < MySQL
6
- end
7
- end
8
- end
1
+ require 'geokit-rails/adapters/mysql'
2
+
3
+ module Geokit
4
+ module Adapters
5
+ class Mysql2 < MySQL
6
+ end
7
+ end
8
+ end
@@ -1,8 +1,8 @@
1
- require 'geokit-rails/adapters/mysql'
2
-
3
- module Geokit
4
- module Adapters
5
- class Mysql2Spatial < MySQL
6
- end
7
- end
8
- end
1
+ require 'geokit-rails/adapters/mysql'
2
+
3
+ module Geokit
4
+ module Adapters
5
+ class Mysql2Spatial < MySQL
6
+ end
7
+ end
8
+ end
@@ -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