From bc3a82fcc609de55579d52ed64642eb575bdda52 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sat, 21 Jan 2017 20:06:04 +0100 Subject: [PATCH] Impl Store::get() interface function --- libimagruby/src/store.rs | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/libimagruby/src/store.rs b/libimagruby/src/store.rs index faeabad6..e1bfabae 100644 --- a/libimagruby/src/store.rs +++ b/libimagruby/src/store.rs @@ -176,7 +176,31 @@ methods!( // On error: Nil + Exception // fn get(sid: RStoreId) -> AnyObject { - unimplemented!() + use entry::FileLockEntryHandle; + let sid = typecheck!(sid or return any NilClass::new()).unwrap().clone(); + + call_on_store! { + store <- itself wrapped inside STORE_WRAPPER, + operation { + match store.get(sid.clone()) { + Err(e) => { + trace_error(&e); + VM::raise(Class::from_existing("RuntimeError"), e.description()); + NilClass::new().to_any_object() + }, + Ok(None) => NilClass::new().to_any_object(), + Ok(Some(entry)) => { + // Take the location (StoreId) of the entry (we know it exists... so this + // is fine) and wrap it into a RFileLockEntry which is then returned to the + // user (as handle) + let sid = entry.get_location().clone(); + let store_handle = itself.get_data(&*STORE_WRAPPER).clone(); + FileLockEntryHandle::new(store_handle, sid).wrap() + }, + } + }, + on fail return NilClass::new().to_any_object() + } } // Get all FileLockEntry of a module from the store