Module: Chimera::GeoIndexes::InstanceMethods

Defined in:
lib/chimera/geo_indexes.rb

Instance Method Summary collapse

Instance Method Details

#create_geo_indexesObject

destroy_geo_indexes



63
64
65
66
67
68
69
70
71
72
73
# File 'lib/chimera/geo_indexes.rb', line 63

def create_geo_indexes
  self.class.defined_indexes.each do |name, props|
    case props[:type]
    when :geo then
      if val = @attributes[name.to_sym] and val.is_a?(Array)
        index_key = self.class.key_for_geo_index(:geo, name, val[0], val[1], props[:step_size])
        self.class.connection(:redis).sadd(index_key, self.id)
      end
    end # case props[:type]
  end # self.class.defined_indexes
end

#destroy_geo_indexesObject



51
52
53
54
55
56
57
58
59
60
61
# File 'lib/chimera/geo_indexes.rb', line 51

def destroy_geo_indexes
  self.class.defined_indexes.each do |name, props|
    case props[:type]
    when :geo then
      if val = @orig_attributes[name.to_sym] and val.is_a?(Array)
        index_key = self.class.key_for_geo_index(:geo, name, val[0], val[1], props[:step_size])
        self.class.connection(:redis).srem(index_key, self.id)
      end
    end # case props[:type]
  end # self.class.defined_indexes
end