Add r_set_header() for FileLockEntry

This commit is contained in:
Matthias Beyer 2017-01-20 15:44:42 +01:00
parent 513cd8f8fc
commit 2ab8f82304

View file

@ -170,7 +170,7 @@ pub mod store {
use std::ops::Deref;
use std::ops::DerefMut;
use ruru::{Class, Object, AnyObject, Boolean, RString, VM};
use ruru::{Class, Object, AnyObject, Boolean, RString, VM, Hash, NilClass};
use libimagstore::store::FileLockEntry as FLE;
use libimagstore::store::EntryHeader;
@ -212,6 +212,30 @@ pub mod store {
itself.get_data(&*FLE_WRAPPER).get_header().clone().wrap()
}
fn r_set_header(hdr: Hash) -> NilClass {
use ruby_utils::IntoToml;
use toml_utils::IntoRuby;
use toml::Value;
let mut header = itself.get_data(&*FLE_WRAPPER).get_header_mut();
if let Err(ref error) = hdr { // raise exception if "hdr" is not a Hash
VM::raise(error.to_exception(), error.description());
return NilClass::new();
}
let hdr = match hdr.unwrap().into_toml() {
Value::Table(t) => *header = EntryHeader::from(t),
_ => {
let ec = Class::from_existing("RuntimeError");
VM::raise(ec, "Something weird happened. Hash seems to be not a Hash");
return NilClass::new();
},
};
NilClass::new()
}
);
wrappable_struct!(EntryHeader, EntryHeaderWrapper, ENTRY_HEADER_WRAPPER);