From c595f5a1e84a92f751a43f74c4c093b0395f2948 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sun, 27 Dec 2015 23:10:36 +0100 Subject: [PATCH] Move File-creation code to Store --- src/storage/file/mod.rs | 88 ----------------------------------------- src/storage/mod.rs | 70 ++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+), 88 deletions(-) diff --git a/src/storage/file/mod.rs b/src/storage/file/mod.rs index 0be95e62..21d5e92e 100644 --- a/src/storage/file/mod.rs +++ b/src/storage/file/mod.rs @@ -32,89 +32,6 @@ pub struct File<'a> { impl<'a> File<'a> { - pub fn new(module: &'a Module<'a>) -> File<'a> { - let f = File { - owning_module: module, - header: FileHeaderData::Null, - data: String::from(""), - id: File::get_new_file_id(), - }; - debug!("Create new File object: {:?}", f); - f - } - - pub fn from_parser_result(module: &'a Module<'a>, id: FileID, header: FileHeaderData, data: String) -> File<'a> { - let f = File { - owning_module: module, - header: header, - data: data, - id: id, - }; - debug!("Create new File object from parser result: {:?}", f); - f - } - - pub fn new_with_header(module: &'a Module<'a>, h: FileHeaderData) -> File<'a> { - let f = File { - owning_module: module, - header: h, - data: String::from(""), - id: File::get_new_file_id(), - }; - debug!("Create new File object with header: {:?}", f); - f - } - - pub fn new_with_data(module: &'a Module<'a>, d: String) -> File<'a> { - let f = File { - owning_module: module, - header: FileHeaderData::Null, - data: d, - id: File::get_new_file_id(), - }; - debug!("Create new File object with data: {:?}", f); - f - } - - pub fn new_with_content(module: &'a Module<'a>, h: FileHeaderData, d: String) -> File<'a> { - let f = File { - owning_module: module, - header: h, - data: d, - id: File::get_new_file_id(), - }; - debug!("Create new File object with content: {:?}", f); - f - } - - /** - * Call editor on the file - * - * Return true if exit code from editor was good (and content was changed), false otherwise. - */ - pub fn edit(rt: &Runtime) { - unimplemented!() - } - - /** - * Call editor on the file contents, but don't include the header inside the editor call. - * - * Return true if exit code from editor was good (and content was changed), false otherwise. - */ - pub fn edit_contents(rt: &Runtime) -> bool { - } - - /** - * Make file persistent. - * - * Retreive store path from the runtime, file id is already available in self. - * - * Return true if action succeeded, false otherwise. - */ - pub fn persist(rt: &Runtime) -> bool { - unimplemented!() - } - pub fn header(&self) -> FileHeaderData { self.header.clone() } @@ -139,11 +56,6 @@ impl<'a> File<'a> { r.is_match(&self.data[..]) || self.header.matches_with(r) } - fn get_new_file_id() -> FileID { - use uuid::Uuid; - let hash = FileHash::from(Uuid::new_v4().to_hyphenated_string()); - FileID::new(FileIDType::UUID, hash) - } } impl<'a> Display for File<'a> { diff --git a/src/storage/mod.rs b/src/storage/mod.rs index 16fbe4f6..de86fe99 100644 --- a/src/storage/mod.rs +++ b/src/storage/mod.rs @@ -6,8 +6,13 @@ pub mod file; pub mod parser; pub mod json; +use module::Module; use storage::file::File; use storage::file::id::FileID; +use storage::file::id_type::FileIDType; +use storage::file::hash::FileHash; +use storage::parser::{FileHeaderParser, Parser, ParserError}; +use storage::file::header::data::FileHeaderData; type Cache<'a> = HashMap>>; @@ -23,4 +28,69 @@ impl<'a> Store<'a> { } } + pub fn new_file(&self, module: &'a Module<'a>) -> File<'a> { + let f = File { + owning_module: module, + header: FileHeaderData::Null, + data: String::from(""), + id: self.get_new_file_id(), + }; + debug!("Create new File object: {:?}", f); + f + } + + pub fn new_file_from_parser_result(&self, module: &'a Module<'a>, id: FileID, header: FileHeaderData, data: String) -> File<'a> { + let f = File { + owning_module: module, + header: header, + data: data, + id: id, + }; + debug!("Create new File object from parser result: {:?}", f); + f + } + + pub fn new_file_with_header(&self, module: &'a Module<'a>, h: FileHeaderData) -> File<'a> { + let f = File { + owning_module: module, + header: h, + data: String::from(""), + id: self.get_new_file_id(), + }; + debug!("Create new File object with header: {:?}", f); + f + } + + pub fn new_file_with_data(&self, module: &'a Module<'a>, d: String) -> File<'a> { + let f = File { + owning_module: module, + header: FileHeaderData::Null, + data: d, + id: self.get_new_file_id(), + }; + debug!("Create new File object with data: {:?}", f); + f + } + + pub fn new_file_with_content(&self, module: &'a Module<'a>, h: FileHeaderData, d: String) -> File<'a> { + let f = File { + owning_module: module, + header: h, + data: d, + id: self.get_new_file_id(), + }; + debug!("Create new File object with content: {:?}", f); + f + } + + pub fn persist(&self, file: &File) -> bool { + unimplemented!() + } + + fn get_new_file_id(&self) -> FileID { + use uuid::Uuid; + let hash = FileHash::from(Uuid::new_v4().to_hyphenated_string()); + FileID::new(FileIDType::UUID, hash) + } + }