Rewrite code to wrap StoreHandle properly
This commit is contained in:
parent
3a90077777
commit
d047b6663b
1 changed files with 30 additions and 19 deletions
|
@ -32,15 +32,20 @@ use util::Unwrap;
|
||||||
|
|
||||||
use storeid::RStoreId;
|
use storeid::RStoreId;
|
||||||
use entry::RFileLockEntry;
|
use entry::RFileLockEntry;
|
||||||
|
use cache::StoreHandle;
|
||||||
|
|
||||||
wrappable_struct!(Store, StoreWrapper, STORE_WRAPPER);
|
wrappable_struct!(StoreHandle, StoreWrapper, STORE_WRAPPER);
|
||||||
class!(RStore);
|
class!(RStore);
|
||||||
impl_wrap!(Store, STORE_WRAPPER);
|
impl_wrap!(StoreHandle, STORE_WRAPPER);
|
||||||
impl_unwrap!(RStore, Store, STORE_WRAPPER);
|
impl_unwrap!(RStore, StoreHandle, STORE_WRAPPER);
|
||||||
impl_verified_object!(RStore);
|
impl_verified_object!(RStore);
|
||||||
|
|
||||||
macro_rules! call_on_store_by_handle {
|
macro_rules! call_on_store_by_handle {
|
||||||
($store_handle:ident -> $name:ident -> $operation:block) => {{
|
($store_handle:ident -> $name:ident -> $operation:block) => {{
|
||||||
|
call_on_store_by_handle!($store_handle -> $name -> $operation on fail return NilClass::new().to_any_object())
|
||||||
|
}};
|
||||||
|
|
||||||
|
($store_handle:ident -> $name:ident -> $operation:block on fail return $ex:expr) => {{
|
||||||
use cache::RUBY_STORE_CACHE;
|
use cache::RUBY_STORE_CACHE;
|
||||||
|
|
||||||
let arc = RUBY_STORE_CACHE.clone();
|
let arc = RUBY_STORE_CACHE.clone();
|
||||||
|
@ -53,22 +58,26 @@ macro_rules! call_on_store_by_handle {
|
||||||
None => {
|
None => {
|
||||||
VM::raise(Class::from_existing("RuntimeError"),
|
VM::raise(Class::from_existing("RuntimeError"),
|
||||||
"Tried to operate on non-existing object");
|
"Tried to operate on non-existing object");
|
||||||
NilClass::new().to_any_object()
|
$ex
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
VM::raise(Class::from_existing("RuntimeError"), e.description());
|
VM::raise(Class::from_existing("RuntimeError"), e.description());
|
||||||
NilClass::new().to_any_object()
|
$ex
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}}
|
}};
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! call_on_store {
|
macro_rules! call_on_store {
|
||||||
|
($itself:ident ($wrapper:ident) -> $name:ident -> $operation:block on fail return $ex:expr) => {{
|
||||||
|
let handle = $itself.get_data(&*$wrapper);
|
||||||
|
call_on_store_by_handle!(handle -> $name -> $operation on fail return $ex)
|
||||||
|
}};
|
||||||
($itself:ident ($wrapper:ident) -> $name:ident -> $operation:block) => {{
|
($itself:ident ($wrapper:ident) -> $name:ident -> $operation:block) => {{
|
||||||
let handle = $itself.get_data(&*$wrapper).store_handle();
|
let handle = $itself.get_data(&*$wrapper);
|
||||||
call_on_store_by_handle!(handle -> $name -> $operation)
|
call_on_store_by_handle!(handle -> $name -> $operation)
|
||||||
}};
|
}};
|
||||||
}
|
}
|
||||||
|
@ -178,12 +187,13 @@ methods!(
|
||||||
let old = typecheck!(old).unwrap().clone();
|
let old = typecheck!(old).unwrap().clone();
|
||||||
let nw = typecheck!(nw).unwrap().clone();
|
let nw = typecheck!(nw).unwrap().clone();
|
||||||
|
|
||||||
if let Err(e) = itself.get_data(&*STORE_WRAPPER).move_by_id(old, nw) {
|
call_on_store!(itself (STORE_WRAPPER) -> store -> {
|
||||||
trace_error(&e);
|
if let Err(e) = store.move_by_id(old, nw) {
|
||||||
VM::raise(Class::from_existing("RuntimeError"), e.description());
|
trace_error(&e);
|
||||||
}
|
VM::raise(Class::from_existing("RuntimeError"), e.description());
|
||||||
|
}
|
||||||
NilClass::new()
|
NilClass::new()
|
||||||
|
} on fail return NilClass::new())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the path of the store object
|
// Get the path of the store object
|
||||||
|
@ -193,12 +203,13 @@ methods!(
|
||||||
// A RString
|
// A RString
|
||||||
//
|
//
|
||||||
fn path() -> RString {
|
fn path() -> RString {
|
||||||
itself.get_data(&*STORE_WRAPPER)
|
call_on_store!(itself (STORE_WRAPPER) -> store -> {
|
||||||
.path()
|
store.path()
|
||||||
.clone()
|
.clone()
|
||||||
.to_str()
|
.to_str()
|
||||||
.map(RString::new)
|
.map(RString::new)
|
||||||
.unwrap_or(RString::new(""))
|
.unwrap_or(RString::new(""))
|
||||||
|
} on fail return RString::new(""))
|
||||||
}
|
}
|
||||||
|
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in a new issue