Module: Ohm::Geoindex
- Defined in:
- lib/ohm/geoindex.rb
Defined Under Namespace
Modules: ClassMethods
Constant Summary collapse
- VERSION =
"0.0.3"
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.included(model) ⇒ Object
7 8 9 10 11 12 13 14 15 |
# File 'lib/ohm/geoindex.rb', line 7 def self.included(model) begin Ohm.redis.call!('GEOADD') rescue RuntimeError => e raise "This version of Redis (#{Ohm.redis.url}) does not support the geospatial API." if e. =~ /unknown command/ end model.extend(ClassMethods) end |
Instance Method Details
#delete ⇒ Object
28 29 30 31 |
# File 'lib/ohm/geoindex.rb', line 28 def delete redis.call('ZREM', self.class.key[:geoindex], self.id) super end |
#save ⇒ Object
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/ohm/geoindex.rb', line 17 def save super redis.queue('MULTI') redis.queue('ZREM', self.class.key[:geoindex], self.id) coordinates = self.class.instance_variable_get('@geoindex').map { |d| attributes[d] } redis.queue('GEOADD', self.class.key[:geoindex], *coordinates, self.id) redis.queue('EXEC') redis.commit self end |