Class: Origen::Database::KeyValueStore
- Defined in:
- lib/origen/database/key_value_store.rb
Instance Attribute Summary collapse
-
#database ⇒ Object
readonly
Returns the parent database (the application’s collection of key-value stores).
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#[](key) ⇒ Object
Read a value from the store.
-
#[]=(key, val) ⇒ Object
Persist a new value to the store.
-
#initialize(database, name) ⇒ KeyValueStore
constructor
A new instance of KeyValueStore.
- #persisted? ⇒ Boolean
- #record_refresh ⇒ Object
-
#refresh ⇒ Object
Force a refresh of the database.
-
#stale? ⇒ Boolean
Returns true if the database is due a time-based refresh, note that this has no bearing on whether or not someone else has committed to the store since the last refresh.
Constructor Details
#initialize(database, name) ⇒ KeyValueStore
Returns a new instance of KeyValueStore.
9 10 11 12 |
# File 'lib/origen/database/key_value_store.rb', line 9 def initialize(database, name) @name = name @database = database end |
Instance Attribute Details
#database ⇒ Object (readonly)
Returns the parent database (the application’s collection of key-value stores)
7 8 9 |
# File 'lib/origen/database/key_value_store.rb', line 7 def database @database end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/origen/database/key_value_store.rb', line 4 def name @name end |
Instance Method Details
#[](key) ⇒ Object
Read a value from the store
15 16 17 18 |
# File 'lib/origen/database/key_value_store.rb', line 15 def [](key) refresh if stale? store[key] end |
#[]=(key, val) ⇒ Object
Persist a new value to the store
21 22 23 24 25 26 |
# File 'lib/origen/database/key_value_store.rb', line 21 def []=(key, val) refresh if persisted? store[key] = val save_to_file val end |
#persisted? ⇒ Boolean
53 54 55 |
# File 'lib/origen/database/key_value_store.rb', line 53 def persisted? database.persisted? end |
#record_refresh ⇒ Object
36 37 38 39 |
# File 'lib/origen/database/key_value_store.rb', line 36 def record_refresh database.record_refresh(name) @store = nil end |
#refresh ⇒ Object
Force a refresh of the database
29 30 31 32 33 34 |
# File 'lib/origen/database/key_value_store.rb', line 29 def refresh unless @uncommitted || !persisted? dssc.check_out(file, version: 'Trunk', force: true) record_refresh end end |
#stale? ⇒ Boolean
Returns true if the database is due a time-based refresh, note that this has no bearing on whether or not someone else has committed to the store since the last refresh
44 45 46 47 48 49 50 51 |
# File 'lib/origen/database/key_value_store.rb', line 44 def stale? if persisted? t = database.time_since_refresh(name) !t || store[:refresh_interval_in_minutes] == 0 || t > store[:refresh_interval_in_minutes] else false end end |