module Ohm::Geoindex

Constants

VERSION

Public Class Methods

included(model) click to toggle source
# 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.message =~ /unknown command/
  end

  model.extend(ClassMethods)
end

Public Instance Methods

delete() click to toggle source
Calls superclass method
# File lib/ohm/geoindex.rb, line 28
def delete
  redis.call('ZREM', self.class.key[:geoindex], self.id)
  super
end
save() click to toggle source
Calls superclass method
# 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