ohm-geoindex 0.0.1 → 0.0.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a5b65c68b782f3ddb94c7699e53c798dc576bb4f
4
- data.tar.gz: b04e62c93ac40539b1768db926ec2c123dac4942
3
+ metadata.gz: b0df31f7ce55dccb5db41ff451c27b638b601697
4
+ data.tar.gz: da98c5300d8050312ad692499ec26d7d91d35c9d
5
5
  SHA512:
6
- metadata.gz: c604e68cd439e13922f828b0d4661c8daabb5ef331be92c4d73f7f635637d537f8e58937b5e926d5907dcd879daaf820ec657ac3cdcfe6162a2b60c8eeea8c16
7
- data.tar.gz: 67d6b3dfeacec7a30d7a1c7314227b81a0e3ffde14b875d92c027063493e40b383247f4837abe571d613797b36cc55c1f6a1727e4e45acbeab70881de7b33fa4
6
+ metadata.gz: da972d8ea43b074973b1c80e3ca08cd4acce50da15ddfe8b9c6ae5306952dfec8137cbfc972b9142e33600e58c01757bc4ca49213c487878e5eb14131fe2e76b
7
+ data.tar.gz: d333e5d8359ccc5e24684516633ab1ba2ae6396dcafa35e911caf167496289b47f7e2999d992aa18d681e6fa52d6f54229d7f9a0bc8f465151ece172b8920956
data/README.md CHANGED
@@ -5,7 +5,7 @@ ohm-geoindex
5
5
 
6
6
  <!-- [![Build Status](https://travis-ci.org/slowernet/ohm-geoindex.png?branch=master)](https://travis-ci.org/slowernet/ohm-geoindex) -->
7
7
 
8
- A plugin for [Ohm](https://github.com/soveran/ohm) models which enables radius queries via the Redis geospatial API.
8
+ A plugin for [Ohm](https://github.com/soveran/ohm) models which enables basic geospatial queries via the Redis [geohashing](http://redis.io/commands#geo) [API](http://cristian.regolo.cc/2015/07/07/introducing-the-geo-api-in-redis.html).
9
9
 
10
10
  Setup
11
11
  -----
@@ -13,50 +13,59 @@ Setup
13
13
  1. Add the gem:
14
14
 
15
15
  ```ruby
16
- gem 'ohm-geoindex'
16
+ gem 'ohm-geoindex', require: 'ohm/geoindex'
17
17
  ````
18
18
 
19
- 1. Include the module in your model:
19
+ 2. Include the module in your model and specify the attributes to be indexed. (Note that `(longitude, latitude)` is the ordering convention used throughout the geo API.)
20
20
 
21
21
  ```ruby
22
- include Ohm::Geoindex
23
- ```
24
-
25
- 1. Add a geospatial index to your model with the following:
22
+ class Beach < Ohm::Model
23
+ include Ohm::Geoindex
26
24
 
27
- ```ruby
28
- geoindex [:longitude, :latitude] # :longitude, :latitude are attributes
25
+ attribute :latitude
26
+ attribute :longitude
27
+ geoindex [:longitude, :latitude]
28
+ end
29
29
  ```
30
30
 
31
- Note that `(lon,lat)` is the universal ordering convention for the Redis geospatial API.
32
-
33
31
  Usage
34
32
  -----
35
33
 
36
34
  To perform a radius query, use the `within` class method.
37
35
 
38
36
  ```ruby
39
- @manly = Beach.create(latitude: -33.797948, longitude: 151.289414)
40
- @bondi = Beach.create(latitude: -33.891472, longitude: 151.277243)
41
- @coogee = Beach.create(latitude: -33.921017, longitude: 151.257566) # ~14km from manly
37
+ >> @manly = Beach.create(latitude: -33.797948, longitude: 151.289414)
38
+ >> @bondi = Beach.create(latitude: -33.891472, longitude: 151.277243)
39
+ >> @coogee = Beach.create(latitude: -33.921017, longitude: 151.257566) # ~14km from manly
42
40
 
43
- >> Beach.within(@coogee, '10 km', 'asc')
44
- => [@coogee, @bondi]
45
- >> Beach.within(@coogee, '10 mi', 'desc')
41
+ >> Beach.within(@coogee, '10 mi', sort: 'desc')
46
42
  => [@manly, @bondi, @coogee]
47
- >> Beach.within([151.257566, -33.921017], '10 mi', 'asc') # coords are @coogee's
43
+ >> Beach.within(@coogee, '10 km', sort: 'asc', withdist: true)
44
+ => [@coogee, @bondi]
45
+ >> Beach.within([151.257566, -33.921017], '10 mi', sort: 'asc') # coords are @coogee's
48
46
  => [@coogee, @bondi, @manly]
49
47
  ```
50
48
 
51
- See the Redis docs for [`GEORADIUS`](http://redis.io/commands/georadius) and [`GEOADD`](http://redis.io/commands/geoadd) for radius unit syntax.
49
+ See the Redis docs for [`GEORADIUS`](http://redis.io/commands/georadius) and [`GEOADD`](http://redis.io/commands/geoadd) for allowed unit syntax.
52
50
 
53
51
  Tests
54
- --------------
52
+ -----
55
53
 
56
- `rake` will attempt to start a redis binary at ./test/redis-server at port 7771 for the duration of the test run.
54
+ Because the geo API is only currently available in Redis' unstable branch, `rake test` attempts to start a local redis binary at ./test/redis-server port 7771 for the test run.
57
55
 
58
56
  Requirements
59
57
  ------------
60
58
 
61
59
  This plugin works with Ohm >= 2.2.0.
62
60
 
61
+ Changelog
62
+ ---------
63
+
64
+ 0.0.2
65
+
66
+ * Correct implicit expectation of indexed attribute names.
67
+
68
+ 0.0.1
69
+
70
+ * Initial release
71
+
data/Rakefile CHANGED
@@ -3,7 +3,7 @@ require "rake/testtask"
3
3
 
4
4
  REDIS_PID = File.join(File.dirname(__FILE__), "test", "tmp", "redis.pid")
5
5
  REDIS_LOG = File.join(File.dirname(__FILE__), "test", "tmp", "redis.log")
6
- REDIS_PORT = 7771
6
+ REDIS_PORT = ENV['REDIS_PORT'] || 7771
7
7
 
8
8
  task :default => [:setup, :_test, :teardown]
9
9
 
data/lib/ohm/geoindex.rb CHANGED
@@ -2,7 +2,7 @@ require 'ohm'
2
2
 
3
3
  module Ohm
4
4
  module Geoindex
5
- VERSION = "0.0.1"
5
+ VERSION = "0.0.2"
6
6
 
7
7
  def self.included(model)
8
8
  begin
@@ -18,7 +18,8 @@ module Ohm
18
18
  super
19
19
  redis.queue('MULTI')
20
20
  redis.queue('ZREM', self.class.key[:geoindex], self.id)
21
- redis.queue('GEOADD', self.class.key[:geoindex], self.longitude, self.latitude, self.id)
21
+ coordinates = self.class.instance_variable_get('@geoindex').map { |d| attributes[d] }
22
+ redis.queue('GEOADD', self.class.key[:geoindex], *coordinates, self.id)
22
23
  redis.queue('EXEC')
23
24
  redis.commit
24
25
  self
@@ -36,6 +37,8 @@ module Ohm
36
37
 
37
38
  def within(center, radius, withdist: nil, sort: nil)
38
39
  raise IndexNotFound unless @geoindex
40
+ raise raise ArgumentError, "center must be a set of coordinates or model already in the index." unless center
41
+
39
42
  args = center.is_a?(self.ancestors.first) ? ['GEORADIUSBYMEMBER', key[:geoindex], center.id] : ['GEORADIUS', key[:geoindex], *center]
40
43
  args << parse_radius(radius)
41
44
  args << sort if sort
data/ohm-geoindex.gemspec CHANGED
@@ -3,7 +3,7 @@ require File.expand_path('../lib/ohm/geoindex', __FILE__)
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'ohm-geoindex'
5
5
  s.version = Ohm::Geoindex::VERSION
6
- s.summary = %q{Geoindices for Ohm (on Redis 3.2+)}
6
+ s.summary = %q{Geoindices for Ohm::Model (on Redis 3.2+)}
7
7
  s.author = "Eliot Shepard"
8
8
  s.email = "eshepard@slower.net"
9
9
  s.files = `git ls-files`.split("\n")
@@ -7,17 +7,17 @@ Ohm.redis = Redic.new(ENV["REDIS_URL"])
7
7
  class Beach < Ohm::Model
8
8
  include Ohm::Geoindex
9
9
 
10
- attribute :longitude
11
- attribute :latitude
12
- geoindex [:longitude, :latitude]
10
+ attribute :lng
11
+ attribute :lat
12
+ geoindex [:lng, :lat]
13
13
  end
14
14
 
15
15
  class GeoindexTest < Test::Unit::TestCase
16
16
  def setup
17
17
  Ohm.flush
18
- @manly = Beach.create(longitude: 151.289414, latitude: -33.797948)
19
- @bondi = Beach.create(longitude: 151.277243, latitude: -33.891472)
20
- @coogee = Beach.create(longitude: 151.257566, latitude: -33.921017) # ~14km from manly
18
+ @manly = Beach.create(lng: 151.289414, lat: -33.797948)
19
+ @bondi = Beach.create(lng: 151.277243, lat: -33.891472)
20
+ @coogee = Beach.create(lng: 151.257566, lat: -33.921017) # ~14km from manly
21
21
  end
22
22
 
23
23
  def test_without_sort
@@ -48,7 +48,7 @@ class GeoindexTest < Test::Unit::TestCase
48
48
 
49
49
  def test_index_update
50
50
  a = Ohm.redis.call('ZSCORE', @bondi.class.key[:geoindex], @bondi.id)
51
- @bondi.update(latitude: -33.921017, longitude: 151.257566) # bondi moves to coogee
51
+ @bondi.update(lat: -33.921017, lng: 151.257566) # bondi moves to coogee
52
52
  b = Ohm.redis.call('ZSCORE', @bondi.class.key[:geoindex], @bondi.id)
53
53
  assert_not_equal(a, b)
54
54
  c = Ohm.redis.call('ZSCORE', @bondi.class.key[:geoindex], @coogee.id)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ohm-geoindex
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eliot Shepard
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-18 00:00:00.000000000 Z
11
+ date: 2015-07-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ohm
@@ -77,5 +77,5 @@ rubyforge_project:
77
77
  rubygems_version: 2.4.5
78
78
  signing_key:
79
79
  specification_version: 4
80
- summary: Geoindices for Ohm (on Redis 3.2+)
80
+ summary: Geoindices for Ohm::Model (on Redis 3.2+)
81
81
  test_files: []