class Origen::Database::KeyValueStores
Attributes
Returns the application that owns the database
Public Class Methods
Source
# File lib/origen/database/key_value_stores.rb, line 7 def initialize(app, options = {}) options = { persist: true }.merge(options) @app = app @persist = options[:persist] end
Public Instance Methods
Source
# File lib/origen/database/key_value_stores.rb, line 89 def has_key?(key) stores.include? key end
Source
# File lib/origen/database/key_value_stores.rb, line 15 def inspect if persisted? app == Origen ? "Origen's Global Database" : "< #{app.class}'s Database >" else app == Origen ? "Origen's Global Session" : "< #{app.class}'s Session >" end end
Source
# File lib/origen/database/key_value_stores.rb, line 68 def method_missing(method, *args, &block) if method.to_s =~ /(=|\(|\)|\.|\[|\]|{|}|\\|\/)/ || [:test, :_system].include?(method) fail "Invalid database name: #{method}" else define_singleton_method(method) do loaded[method] ||= KeyValueStore.new(self, method) end end send(method, *args, &block) end
Used to create new key value stores on the fly.
On first call of a missing method a method is generated to avoid the missing lookup next time, this should be faster for repeated lookups of the same method, e.g. reg
Source
# File lib/origen/database/key_value_stores.rb, line 85 def persisted? @persist end
Source
# File lib/origen/database/key_value_stores.rb, line 55 def record_new_store(name) unless name == :_system || name == :_database _system.refresh s = stores s << name unless s.include?(name) _system[:stores] = s end end
Source
# File lib/origen/database/key_value_stores.rb, line 47 def record_refresh(name) if persisted? t = refresh_table t[name] = Time.now app.session._database[:refresh_table] = t end end
Record that the given store was just refreshed
Source
# File lib/origen/database/key_value_stores.rb, line 24 def refresh if persisted? _system.refresh files = stores.map { |name| send(name).send(:file) } dssc.check_out(files.join(' '), version: 'Trunk', force: true) stores.each { |name| send(name).record_refresh } end nil end
Refresh all stores
Source
# File lib/origen/database/key_value_stores.rb, line 81 def stores _system[:stores] || [] end
Returns the names of all known stores
Source
# File lib/origen/database/key_value_stores.rb, line 36 def time_since_refresh(name) if persisted? if refresh_table[name] ((Time.now - refresh_table[name]) / 60).floor end else Time.now end end
Returns the time in minutes since the given store was last refreshed
Private Instance Methods
Source
# File lib/origen/database/key_value_stores.rb, line 100 def _system @_system ||= KeyValueStore.new(self, :_system) end
Persisted key value store used by the database system
Source
# File lib/origen/database/key_value_stores.rb, line 104 def dssc @dssc ||= Origen::Utility::DesignSync.new end
Source
# File lib/origen/database/key_value_stores.rb, line 108 def loaded @loaded ||= {} end
Source
# File lib/origen/database/key_value_stores.rb, line 95 def refresh_table app.session._database[:refresh_table] ||= {} end