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