require 'fiona7/workspace' require 'fiona7/assert' module Fiona7 module Controllers module RestAPI class WorkspaceController def fetch(id) id = id.to_sym Assert.input( id == :published || id == :rtc, "Workspace does not exist" ) w = Workspace.new(id) return ::JSON.parse(::ActiveSupport::JSON.encode(w)) end def publish(id) raise "Unexpected workspace_id: #{id}" unless id.to_s == "rtc" WriteObj.where(is_edited: 1).each do |obj| begin obj.take obj.release! rescue => e raise "Release impossible of: #{obj.path} because: #{e.message}" end end {'task' => {'id' => '1', 'status' => 'success', 'result' => '1'}} end def delete(id) Assert.contraint(false, "Workspaces cannot be deleted") end def create(values) id = (values[:workspace][:id] || values[:workspace]["id"]) id = (id || :no_id_provided).to_sym Assert.constraint( id == :rtc, "Only rtc workspace can be created" ) w = Workspace.rtc # NOTE: this "creates" a rtc workspace # and breaks publish checker spec ... #WriteObj.root.take ; WriteObj.root.edit ::JSON.parse(::ActiveSupport::JSON.encode(w)) end def all results = [Workspace.published, Workspace.rtc] w = {'results' => results} ::JSON.parse(::ActiveSupport::JSON.encode(w)) end end end end end