lib/scrivito/workspace.rb in scrivito_sdk-1.0.0 vs lib/scrivito/workspace.rb in scrivito_sdk-1.1.0.rc1

- old
+ new

@@ -134,22 +134,43 @@ # Scrivito::Workspace.create(title: "Jane") # @api public # @param [Hash] attributes # @return [Scrivito::Workspace] def self.create(attributes) - workspace_json = CmsRestApi.post("/workspaces", workspace: attributes) + find(create_async(attributes).result['id']) + end - self.find(workspace_json["id"]) + def self.create_async(attributes) + Task.new do + CmsRestApi.task_unaware_request(:post, 'workspaces', workspace: attributes) + end end # Reloads the current workspace to reflect the changes that were made to it concurrently # since it was loaded. # @api public def self.reload current.reload end + # @api public + # + # This method provides a string that can be used as part of a cache key. It changes + # whenever any content ({Scrivito::BasicObj Obj} or {Scrivito::BasicWidget Widget}) + # changes. Due to this, caches using the +cache_key+ are invalidated whenever + # a CMS object in the working copy has been changed. + # + # Scrivito provides the {ScrivitoHelper#scrivito_cache scrivito_cache} method which + # integrates the +cache_key+ with Rails' fragment caching. You might want to check whether + # +scrivito_cache+ satisfies your needs before implementing your own solution. + # + # @return [String] A string that changes whenever the content of the working copy + # changes. + def cache_key + @cache_key ||= Digest::SHA1.hexdigest("#{id}|#{content_state_id}") + end + def self.cache @cache ||= {} end def initialize(workspace_data) @@ -204,25 +225,35 @@ end # Publish the changes that were made to this workspace. # @api public def publish - CmsRestApi.put("#{backend_url}/publish", {}) - + publish_async.result Workspace.published.reload - reset_workspace_if_current end + def publish_async + Task.new do + task_unaware_api_request(:put, '/publish') + end + end + # Rebases the current workspace from the published content in order to integrate the changes # that were published in the meantime. # @api public def rebase - CmsRestApi.put("#{backend_url}/rebase", {}) + rebase_async.result reload end + def rebase_async + Task.new do + task_unaware_api_request(:put, '/rebase') + end + end + # Returns the id of the workspace. # @api public # @return [String] def id @id @@ -339,9 +370,10 @@ # Clear all cached instance variables. @base_revision = nil @memberships = nil @revision = nil + @cache_key = nil end def fetch_workspace_data CmsBackend.instance.find_workspace_data_by_id(id) end