Class: Forecast::IO::Cache::Store
- Inherits:
-
Object
- Object
- Forecast::IO::Cache::Store
- Defined in:
- lib/forecast_io/cache/store.rb
Instance Method Summary collapse
- #fetch(lat, lon, time) ⇒ Object
-
#initialize(config = Cache.configuration) ⇒ Store
constructor
A new instance of Store.
- #store(forecast) ⇒ Object
Constructor Details
#initialize(config = Cache.configuration) ⇒ Store
Returns a new instance of Store.
9 10 11 12 |
# File 'lib/forecast_io/cache/store.rb', line 9 def initialize config = Cache.configuration @config = config @backend = MongoAdaptor.new('forecasts',ForecastData) end |
Instance Method Details
#fetch(lat, lon, time) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/forecast_io/cache/store.rb', line 14 def fetch lat, lon, time @backend.fetch 'position' => { '$near' => [lon,lat], '$maxDistance' => radius }, 'time' => { '$lt' => time+offset, '$gt' => time-offset } rescue Mongo::OperationFailure => error if index_error? error ensure_index! retry else raise end end |
#store(forecast) ⇒ Object
26 27 28 29 |
# File 'lib/forecast_io/cache/store.rb', line 26 def store forecast @backend.insert forecast forecast end |