Class: Routemaster::Dirty::State
- Inherits:
-
Struct
- Object
- Struct
- Routemaster::Dirty::State
- 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
-
#t ⇒ Object
Returns the value of attribute t.
-
#url ⇒ Object
Returns the value of attribute url.
Class Method Summary collapse
-
.get(redis, url) ⇒ Object
Given a
redis
instance, return.
Instance Method Summary collapse
-
#save(redis, expiry) ⇒ Object
Given a
redis
instance, save the state, expiring afterexpiry
seconds.
Instance Attribute Details
#t ⇒ Object
Returns the value of attribute t
9 10 11 |
# File 'lib/routemaster/dirty/state.rb', line 9 def t @t end |
#url ⇒ Object
Returns the value of attribute 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 |