class Soar::Registry::Directory::Provider::Stub

Public Class Methods

new(table: , index: ) click to toggle source

@param [String] table the table name @param [Array<String>] indexes primary key should be the first item

# File lib/soar/registry/directory/provider/stub.rb, line 16
def initialize(table: , index: )
  @interface = Mince::HashyDb::Interface
  @table = table
  @primary_key = index[0]
  @index = index
  @interface.clear
end

Public Instance Methods

fetch(primary_key) click to toggle source

@param [String] primary_key @return [Hash{String => Hash, String, Number, Array}] entry @raise [Soar::Registry:::Directory::Error::NoEntriesFoundError] if primary key not found

# File lib/soar/registry/directory/provider/stub.rb, line 44
def fetch(primary_key)
  adapt_exceptions do
    entry = @interface.get_for_key_with_value(@table, @primary_key, primary_key)
    raise Soar::Registry::Directory::Error::NoEntriesFoundError, "No entries found for #{@primary_key} = #{primary_key}" if entry.nil?
    entry
  end
end
index() click to toggle source

@return [Array<String>] a list of provider specific indexes

# File lib/soar/registry/directory/provider/stub.rb, line 75
def index
  adapt_exceptions do
    [@interface.primary_key.to_s]
    @index
  end
end
put(entry) click to toggle source

@param [Hash{String => Hash, String, Number, Array}] entry @raise [Soar::Registry::Directory::Error::DuplicateEntryError] @return [Boolean]

# File lib/soar/registry/directory/provider/stub.rb, line 29
def put(entry)
  adapt_exceptions do
    if not @interface.get_for_key_with_value(@table, @primary_key, entry[@primary_key])
       @interface.add(@table, entry)
       return true
    end
    raise Soar::Registry::Directory::Error::DuplicateEntryError, "Unable to add duplicate entry for index #{@primary_key} with value #{entry[@primary_key]}"
  end
end

Private Instance Methods

adapt_exceptions() { || ... } click to toggle source
# File lib/soar/registry/directory/provider/stub.rb, line 85
def adapt_exceptions
  begin
    yield
  rescue NoMethodError => e
    raise Soar::Registry::Directory::Error::NetworkingError, 'Networking error'
  end
end