geokit-rails 2.3.1 → 2.3.2

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.

Potentially problematic release.


This version of geokit-rails might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 60cc7291a94e6384a48947ecb040a472b26c0ac6
4
- data.tar.gz: e067b31c96bf53bbe4a3be1f6acf9f490e0c2c16
2
+ SHA256:
3
+ metadata.gz: d8abd196ef01725dfea499611d751fe08d1f42da5473c7896d526b16044e5c7a
4
+ data.tar.gz: aef079a740792c981bb86d07d48c3686b2d939d5ce1792dd50d7d5c4bfe6bc05
5
5
  SHA512:
6
- metadata.gz: 06e80fa935a623e414e484df78abbc3fb8795c59babe7c40acc152a415b0ca12563be5c3bbaca82be6b36701cea934a8d5d9ae79b1a77defd9a5dd7735e71eb3
7
- data.tar.gz: 617c4629c9a48b244dbaa9c8afed2cfb7315de6309e11c1d775892174e5d4166c23158d150a506f6f8f7084c0fd1f42e7549baddc8194d83f4c8e62cf40e59b3
6
+ metadata.gz: 7de113ad53d0ae12a3919337e70ec69d91a59f1ae9147235ee2eb42ccdd20e73438784bba5eb6122da7bb1185e28cd8d321af7a63c654b153ead266ac96d548b
7
+ data.tar.gz: ad3e5699a610b9ef8ef451bd76bef841f36272a96896a04c2610d8cb21603f869a0c670a4754366d8b3df5dc13e3f03a3807f9a96848abe63ae0e30aa45b40e9
@@ -1,3 +1,7 @@
1
+ ## 2.3.2
2
+
3
+ * Fix sqlite3 adapter error
4
+
1
5
  ## 2.3.1
2
6
 
3
7
  * Fix Rails 5.2 deprecation warning
@@ -264,6 +264,12 @@ If you are displaying points on a map, you probably need to query for whatever f
264
264
  Store.in_bounds([sw_point,ne_point]).all
265
265
  ```
266
266
 
267
+ If you want the query to return things that are located on the rectangular bounds, specify the `inclusive` option set to true:
268
+
269
+ ```ruby
270
+ Store.in_bounds([sw_point,ne_point], :inclusive => true).all
271
+ ```
272
+
267
273
  The input to `bounds` can be an array with the two points or a Bounds object. However you provide them, the order should always be the southwest corner, northeast corner of the rectangle. Typically, you will be getting the sw\_point and ne\_point from a map that is displayed on a web page.
268
274
 
269
275
  If you need to calculate the bounding box from a point and radius, you can do that:
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
20
20
  spec.add_dependency 'rails', '>= 3.0'
21
21
  spec.add_dependency 'geokit', '~> 1.5'
22
22
  spec.add_development_dependency "bundler", "> 1.0"
23
- spec.add_development_dependency "simplecov"
23
+ spec.add_development_dependency "simplecov", "~> 0.16.1"
24
24
  spec.add_development_dependency "simplecov-rcov"
25
25
  spec.add_development_dependency 'rake'
26
26
  spec.add_development_dependency 'test-unit'
@@ -141,11 +141,12 @@ module Geokit
141
141
  end
142
142
 
143
143
  def in_bounds(bounds, options = {})
144
+ inclusive = options.delete(:inclusive) || false
144
145
  options[:bounds] = bounds
145
146
  #geo_scope(options)
146
147
  #where(distance_conditions(options))
147
148
  bounds = extract_bounds_from_options(options)
148
- where(bound_conditions(bounds))
149
+ where(bound_conditions(bounds, inclusive))
149
150
  end
150
151
 
151
152
  def by_distance(options = {})
@@ -153,9 +154,9 @@ module Geokit
153
154
  units = extract_units_from_options(options)
154
155
  formula = extract_formula_from_options(options)
155
156
  distance_column_name = distance_sql(origin, units, formula)
156
- with_latlng.order(Arel.sql(
157
- "#{distance_column_name} #{options[:reverse] ? 'DESC' : 'ASC'}"
158
- ))
157
+ with_latlng.order(
158
+ Arel.sql(distance_column_name).send(options[:reverse] ? 'desc' : 'asc')
159
+ )
159
160
  end
160
161
 
161
162
  def with_latlng
@@ -233,7 +234,7 @@ module Geokit
233
234
  # If it's a :within query, add a bounding box to improve performance.
234
235
  # This only gets called if a :bounds argument is not otherwise supplied.
235
236
  def formulate_bounds_from_distance(options, origin, units)
236
- distance = options[:within] if options.has_key?(:within)
237
+ distance = options[:within] if options.has_key?(:within) && options[:within].is_a?(Numeric)
237
238
  distance = options[:range].last-(options[:range].exclude_end?? 1 : 0) if options.has_key?(:range)
238
239
  if distance
239
240
  Geokit::Bounds.from_point_and_radius(origin,distance,:units=>units)
@@ -248,22 +249,39 @@ module Geokit
248
249
  formula = extract_formula_from_options(options)
249
250
  distance_column_name = distance_sql(origin, units, formula)
250
251
 
251
- res = if options.has_key?(:within)
252
- "#{distance_column_name} <= #{options[:within]}"
252
+ if options.has_key?(:within)
253
+ Arel.sql(distance_column_name).lteq(options[:within])
253
254
  elsif options.has_key?(:beyond)
254
- "#{distance_column_name} > #{options[:beyond]}"
255
+ Arel.sql(distance_column_name).gt(options[:beyond])
255
256
  elsif options.has_key?(:range)
256
- "#{distance_column_name} >= #{options[:range].first} AND #{distance_column_name} <#{'=' unless options[:range].exclude_end?} #{options[:range].last}"
257
+ min_condition = Arel.sql(distance_column_name).gteq(options[:range].begin)
258
+ max_condition = if options[:range].exclude_end?
259
+ Arel.sql(distance_column_name).lt(options[:range].end)
260
+ else
261
+ Arel.sql(distance_column_name).lteq(options[:range].end)
262
+ end
263
+ min_condition.and(max_condition)
257
264
  end
258
- Arel::Nodes::SqlLiteral.new("(#{res})") if res.present?
259
265
  end
260
266
 
261
- def bound_conditions(bounds)
267
+ def bound_conditions(bounds, inclusive = false)
268
+ return nil unless bounds
269
+ if inclusive
270
+ lt_operator = :lteq
271
+ gt_operator = :gteq
272
+ else
273
+ lt_operator = :lt
274
+ gt_operator = :gt
275
+ end
262
276
  sw,ne = bounds.sw, bounds.ne
263
- lng_sql = bounds.crosses_meridian? ? "(#{qualified_lng_column_name}<#{ne.lng} OR #{qualified_lng_column_name}>#{sw.lng})" : "#{qualified_lng_column_name}>#{sw.lng} AND #{qualified_lng_column_name}<#{ne.lng}"
264
- res = "#{qualified_lat_column_name}>#{sw.lat} AND #{qualified_lat_column_name}<#{ne.lat} AND #{lng_sql}"
265
- #Arel::Nodes::SqlLiteral.new("(#{res})") if res.present?
266
- res if res.present?
277
+ lat, lng = Arel.sql(qualified_lat_column_name), Arel.sql(qualified_lng_column_name)
278
+ lat.send(gt_operator, sw.lat).and(lat.send(lt_operator, ne.lat)).and(
279
+ if bounds.crosses_meridian?
280
+ lng.send(lt_operator, ne.lng).or(lng.send(gt_operator, sw.lng))
281
+ else
282
+ lng.send(gt_operator, sw.lng).and(lng.send(lt_operator, ne.lng))
283
+ end
284
+ )
267
285
  end
268
286
 
269
287
  # Extracts the origin instance out of the options if it exists and returns
@@ -3,7 +3,7 @@ module Geokit
3
3
  class SQLite < Abstract
4
4
 
5
5
  def self.add_numeric(name)
6
- @@connection.create_function name, 1, :numeric do |func, *args|
6
+ @@connection.create_function name, 1, SQLite3::Constants::TextRep::ANY do |func, *args|
7
7
  func.result = yield(*args)
8
8
  end
9
9
  end
@@ -50,4 +50,4 @@ module Geokit
50
50
 
51
51
  end
52
52
  end
53
- end
53
+ end
@@ -1,3 +1,3 @@
1
1
  module GeokitRails
2
- VERSION = "2.3.1"
2
+ VERSION = "2.3.2"
3
3
  end
@@ -108,6 +108,12 @@ class ActsAsMappableTest < GeokitTestCase
108
108
  assert_equal 5, locations.count
109
109
  end
110
110
 
111
+ def test_find_within_with_column_as_distance
112
+ locations = Location.joins(:company).within(Company.arel_table[:max_distance], origin: @loc_a)
113
+ assert_equal 4, locations.to_a.size
114
+ assert_equal 4, locations.count
115
+ end
116
+
111
117
  def test_find_with_compound_condition
112
118
  #locations = Location.geo_scope(:origin => @loc_a).where("distance < 5 and city = 'Coppell'")
113
119
  locations = Location.within(5, :origin => @loc_a).where("city = 'Coppell'")
@@ -383,6 +389,16 @@ class ActsAsMappableTest < GeokitTestCase
383
389
  assert_equal 2, locations.count
384
390
  end
385
391
 
392
+ def test_find_within_bounds_with_inclusive
393
+ sw = Geokit::LatLng.new(@loc_a.lat,@loc_a.lng)
394
+ ne = sw
395
+ bounds = [sw,ne]
396
+ locations = Location.in_bounds(bounds, :inclusive => false)
397
+ assert_equal 0, locations.count
398
+ locations = Location.in_bounds(bounds, :inclusive => true)
399
+ assert_equal 1, locations.count
400
+ end
401
+
386
402
  def test_find_within_bounds_ordered_by_distance
387
403
  #locations = Location.in_bounds([@sw,@ne], :origin=>@bounds_center).order('distance asc')
388
404
  locations = Location.in_bounds([@sw,@ne]).by_distance(:origin => @bounds_center)
@@ -1,7 +1,9 @@
1
1
  starbucks:
2
2
  id: 1
3
3
  name: Starbucks
4
+ max_distance: 1.7
4
5
 
5
6
  barnes_and_noble:
6
7
  id: 2
7
- name: Barnes & Noble
8
+ name: Barnes & Noble
9
+ max_distance: 2.0
@@ -1,6 +1,7 @@
1
1
  ActiveRecord::Schema.define(:version => 0) do
2
2
  create_table :companies, :force => true do |t|
3
3
  t.column :name, :string
4
+ t.column :max_distance, :float
4
5
  end
5
6
 
6
7
  create_table :locations, :force => true do |t|
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: geokit-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.1
4
+ version: 2.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Noack
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2018-05-04 00:00:00.000000000 Z
14
+ date: 2021-01-08 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rails
@@ -59,16 +59,16 @@ dependencies:
59
59
  name: simplecov
60
60
  requirement: !ruby/object:Gem::Requirement
61
61
  requirements:
62
- - - ">="
62
+ - - "~>"
63
63
  - !ruby/object:Gem::Version
64
- version: '0'
64
+ version: 0.16.1
65
65
  type: :development
66
66
  prerelease: false
67
67
  version_requirements: !ruby/object:Gem::Requirement
68
68
  requirements:
69
- - - ">="
69
+ - - "~>"
70
70
  - !ruby/object:Gem::Version
71
- version: '0'
71
+ version: 0.16.1
72
72
  - !ruby/object:Gem::Dependency
73
73
  name: simplecov-rcov
74
74
  requirement: !ruby/object:Gem::Requirement
@@ -279,8 +279,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
279
279
  - !ruby/object:Gem::Version
280
280
  version: '0'
281
281
  requirements: []
282
- rubyforge_project:
283
- rubygems_version: 2.6.14.1
282
+ rubygems_version: 3.1.4
284
283
  signing_key:
285
284
  specification_version: 4
286
285
  summary: Geokit helpers for rails apps.