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
search(key, value)
click to toggle source
@param [String] key @param [String] value @return [Array<String>] list of matching entries @raise [ArgumentError] if query or index is not specified
# File lib/soar/registry/directory/provider/stub.rb, line 58 def search(key, value) adapt_exceptions do identities = [] @interface.find_all(@table).each { |identity| if identity[key] == value identities << identity else next end } identities 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