Class: GeoMongo::Store
- Inherits:
-
Object
- Object
- GeoMongo::Store
- Defined in:
- lib/geo_mongo.rb
Instance Method Summary collapse
- #[](url) ⇒ Object
- #[]=(url, value) ⇒ Object
- #del(url) ⇒ Object
-
#initialize(server, port, database, collection = "geocache") ⇒ Store
constructor
A new instance of Store.
- #keys ⇒ Object
Constructor Details
#initialize(server, port, database, collection = "geocache") ⇒ Store
Returns a new instance of Store.
6 7 8 9 |
# File 'lib/geo_mongo.rb', line 6 def initialize(server, port, database, collection="geocache") @conn = Mongo::Connection.new(server, port).db(database) @coll = @conn.collection(collection) end |
Instance Method Details
#[](url) ⇒ Object
11 12 13 14 |
# File 'lib/geo_mongo.rb', line 11 def [](url) value = @coll.find_one({:url => url}, :fields => {:_id => 0, :url => 0}) value["value"] unless value.nil? end |
#[]=(url, value) ⇒ Object
16 17 18 |
# File 'lib/geo_mongo.rb', line 16 def []=(url, value) @coll.update({:url => url}, {:url => url, :value => value}, :upsert => true) end |
#del(url) ⇒ Object
24 25 26 |
# File 'lib/geo_mongo.rb', line 24 def del(url) @coll.remove({:url => url}) end |
#keys ⇒ Object
20 21 22 |
# File 'lib/geo_mongo.rb', line 20 def keys @coll.find({},:fields => {:_id => 0, :value => 0}).to_a.collect{|k| k["url"]} end |