Class: Routemaster::Dirty::State

Inherits:
Struct
  • Object
show all
Defined in:
lib/routemaster/dirty/state.rb

Overview

Locale prepresentation of the state of an entity.

  • url (string): the entity's authoritative locator
  • t (datetime, UTC): when the state was last refreshed

Constant Summary collapse

KEY =
'dirtymap:state:%s'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#tObject

Returns the value of attribute t

Returns:

  • (Object)

    the current value of t



9
10
11
# File 'lib/routemaster/dirty/state.rb', line 9

def t
  @t
end

#urlObject

Returns the value of attribute url

Returns:

  • (Object)

    the current value of url



9
10
11
# File 'lib/routemaster/dirty/state.rb', line 9

def url
  @url
end

Class Method Details

.get(redis, url) ⇒ Object

Given a redis instance, return

  • a "blank" state for that URL (with time stamp 0), if the state is unknown; or
  • the entity state, if known.


17
18
19
20
21
# File 'lib/routemaster/dirty/state.rb', line 17

def self.get(redis, url)
  data = redis.get(KEY % url)
  return new(url, 0) if data.nil?
  Marshal.load(data)
end

Instance Method Details

#save(redis, expiry) ⇒ Object

Given a redis instance, save the state, expiring after expiry seconds.



25
26
27
28
# File 'lib/routemaster/dirty/state.rb', line 25

def save(redis, expiry)
  data = Marshal.dump(self)
  redis.set(KEY % url, data, ex: expiry)
end