require 'fiona7/version_helper' require 'fiona7/assert' module Fiona7 class Workspace attr_reader :id, :title class << self def rtc self.new(:rtc) end def published self.new(:published) end end def initialize(id) @id = id.to_sym Assert.constraint( @id == :rtc || @id == :published, "Only published and rtc workspaces are possible" ) @version_helper = VersionHelper.new(@id) end def title if self.id == :rtc 'Edited' else nil end end def revision_id self.version_helper.revision_id end def content_state_id self.version_helper.content_state_id end def base_revision_id self.version_helper.base_revision_id if self.id == :rtc end def base_content_state_id self.version_helper.base_content_state_id if self.id == :rtc end def memberships {} end def as_json(*options) r = { id: self.id, title: self.title, revision_id: self.revision_id, content_state_id: self.content_state_id, memberships: self.memberships } r.merge!({ base_revision_id: self.base_revision_id, base_content_state_id: self.base_content_state_id }) if self.id == :rtc r.as_json(*options) end protected attr_reader :version_helper end end