class Origen::Database::KeyValueStores

Attributes

app[R]

Returns the application that owns the database

Public Class Methods

new(app, options = {}) click to toggle 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

has_key?(key) click to toggle source
# File lib/origen/database/key_value_stores.rb, line 89
def has_key?(key)
  stores.include? key
end
inspect() click to toggle 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
method_missing(method, *args, &block) click to toggle source

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

# 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
persisted?() click to toggle source
# File lib/origen/database/key_value_stores.rb, line 85
def persisted?
  @persist
end
record_new_store(name) click to toggle 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
record_refresh(name) click to toggle source

Record that the given store was just refreshed

# 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
refresh() click to toggle source

Refresh all stores

# 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
stores() click to toggle source

Returns the names of all known stores

# File lib/origen/database/key_value_stores.rb, line 81
def stores
  _system[:stores] || []
end
time_since_refresh(name) click to toggle source

Returns the time in minutes since the given store was last refreshed

# 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

Private Instance Methods

_system() click to toggle source

Persisted key value store used by the database system

# File lib/origen/database/key_value_stores.rb, line 100
def _system
  @_system ||= KeyValueStore.new(self, :_system)
end
dssc() click to toggle source
# File lib/origen/database/key_value_stores.rb, line 104
def dssc
  @dssc ||= Origen::Utility::DesignSync.new
end
loaded() click to toggle source
# File lib/origen/database/key_value_stores.rb, line 108
def loaded
  @loaded ||= {}
end
refresh_table() click to toggle source
# File lib/origen/database/key_value_stores.rb, line 95
def refresh_table
  app.session._database[:refresh_table] ||= {}
end