Class: Forecast::IO::Cache::Store

Inherits:
Object
  • Object
show all
Defined in:
lib/forecast_io/cache/store.rb

Instance Method Summary collapse

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 = PGAdaptor.new('forecasts', ForecastData)
end

Instance Method Details

#fetch(lat, lon, time) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/forecast_io/cache/store.rb', line 14

def fetch lat, lon, time
  @backend.fetch Sequel.lit(<<-SQL),
    time >= :start AND time <= :end AND earth_box(
      ll_to_earth(:lat, :lon), :radius
    ) @> ll_to_earth(
      latitude,
      longitude
    )
    SQL
    start: time - offset,
    end: time + offset,
    lat: lat,
    lon: lon,
    radius: radius
end

#store(forecast) ⇒ Object



30
31
32
33
# File 'lib/forecast_io/cache/store.rb', line 30

def store forecast
  @backend.insert forecast
  forecast
end