From 2ab8f8230457b4c4ef81f72b5a110fa71d147699 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Fri, 20 Jan 2017 15:44:42 +0100 Subject: [PATCH] Add r_set_header() for FileLockEntry --- 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 e08ad616..6cded4bd 100644 --- a/libimagruby/src/store.rs +++ b/libimagruby/src/store.rs @@ -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);