diff options
author | James Lopez <james@jameslopez.es> | 2016-03-07 20:26:15 +0300 |
---|---|---|
committer | James Lopez <james@jameslopez.es> | 2016-03-07 20:26:15 +0300 |
commit | f9eb3fc0aa3c99fd36d3f344dc95f6b4edad5e07 (patch) | |
tree | 2fd2c6327cc928d75c20fb8851f7be7290b74b63 /app/services/projects/import_export | |
parent | 99f08b3f727e9d155ab10ad285fe48e0279fb79e (diff) |
WIP - initial export service and spec
Diffstat (limited to 'app/services/projects/import_export')
-rw-r--r-- | app/services/projects/import_export/export_service.rb | 15 | ||||
-rw-r--r-- | app/services/projects/import_export/project_tree_saver.rb | 42 |
2 files changed, 57 insertions, 0 deletions
diff --git a/app/services/projects/import_export/export_service.rb b/app/services/projects/import_export/export_service.rb new file mode 100644 index 00000000000..c89dd3d12ed --- /dev/null +++ b/app/services/projects/import_export/export_service.rb @@ -0,0 +1,15 @@ +module Projects + module ImportExport + class ExportService < BaseService + def execute(options = {}) + save_project_tree + end + + private + + def save_project_tree + Projects::ImportExport::ProjectTreeSaver.save(project: project) + end + end + end +end diff --git a/app/services/projects/import_export/project_tree_saver.rb b/app/services/projects/import_export/project_tree_saver.rb new file mode 100644 index 00000000000..4801c791ffe --- /dev/null +++ b/app/services/projects/import_export/project_tree_saver.rb @@ -0,0 +1,42 @@ +module Projects + module ImportExport + class ProjectTreeSaver + attr_reader :full_path + + def initialize(project: ) + @project = project + end + + def save + @full_path = File.join(export_path, project_filename) + save_to_disk + end + + private + + def save_to_disk + FileUtils.mkdir_p(export_path) + File.write(full_path, project_json_tree) + true + rescue + #TODO: handle error + false + end + + def export_path + @export_path ||= ImportExport.export_path(@project.name) + end + + def project_filename + # TODO sanitize name + "#{@project.name}.json" + end + + def project_json_tree + # TODO confirm children, also add subchildren (i.e comments) + # TODO confirm atts for children + @project.to_json(only: ImportExport.project_atts, include: ImportExport.project_tree) + end + end + end +end |