Class: Scrivito::Workspace
- Inherits:
-
Object
- Object
- Scrivito::Workspace
- Extended by:
- ActiveModel::Naming
- Defined in:
- lib/scrivito/workspace.rb,
lib/scrivito/workspace/publish_checker.rb
Overview
This class represents a CMS workspace, called “working copy” in the UI. A working copy lets editors create and modify content independently of the published content or other working copies. On creation, a working copy is based on the currently published content.
Class Method Summary collapse
-
.all ⇒ Array<Scrivito::Workspace>
Returns all workspaces.
-
.create(attributes) ⇒ Scrivito::Workspace
Create a new workspace.
-
.current ⇒ Scrivito::Workspace
Returns the currently used workspace.
-
.current=(workspace) ⇒ Object
Set the workspace to use for subsequent workspace operations.
-
.find(id) ⇒ Scrivito::Workspace
Find a workspace by its id.
-
.find_by_title(title) ⇒ Scrivito::Workspace
Find a workspace by its title.
-
.reload ⇒ Object
Reloads the current workspace to reflect the changes that were made to it concurrently since it was loaded.
-
.use(id_or_title)
Find a workspace by its id or title and set it as the currently used workspace.
Instance Method Summary collapse
-
#destroy ⇒ Object
Destroy this workspace.
-
#id ⇒ String
Returns the id of the workspace.
-
#memberships ⇒ MembershipCollection
Returns the memberships (users and their roles) of this workspace.
-
#objs ⇒ ObjCollection
Returns an ObjCollection of this working copy for accessing its CMS objects.
-
#publish ⇒ Object
Publish the changes that were made to this workspace.
-
#rebase ⇒ Object
Rebases the current workspace from the published content in order to integrate the changes that were published in the meantime.
-
#reload ⇒ Object
Reloads this workspace to reflect the changes that were made to it concurrently since it was loaded.
-
#title ⇒ String
Returns the title of the workspace if present.
-
#update(attributes) ⇒ Scrivito::Workspace
Updates the attributes of this workspace.
Class Method Details
.all ⇒ Array<Scrivito::Workspace>
Returns all workspaces.
43 44 45 46 47 48 49 |
# File 'lib/scrivito/workspace.rb', line 43 def self.all result_json = CmsRestApi.get('/workspaces') result_json['results'].map do |raw_data| Workspace.new(WorkspaceData.new(raw_data)) end end |
.create(attributes) ⇒ Scrivito::Workspace
Create a new workspace.
134 135 136 137 138 |
# File 'lib/scrivito/workspace.rb', line 134 def self.create(attributes) workspace_json = CmsRestApi.post("/workspaces", workspace: attributes) self.find(workspace_json["id"]) end |
.current ⇒ Scrivito::Workspace
Returns the currently used workspace.
32 33 34 35 36 37 38 |
# File 'lib/scrivito/workspace.rb', line 32 def self.current if @current.respond_to? :call @current = @current.call else @current ||= published end end |
.current=(workspace) ⇒ Object
Set the workspace to use for subsequent workspace operations.
21 22 23 |
# File 'lib/scrivito/workspace.rb', line 21 def self.current=(workspace) @current = workspace end |
.find(id) ⇒ Scrivito::Workspace
Find a workspace by its id.
77 78 79 80 81 82 83 |
# File 'lib/scrivito/workspace.rb', line 77 def self.find(id) cache.fetch(id) do workspace_data = CmsBackend.instance.find_workspace_data_by_id(id) from_workspace_data(id, workspace_data) end end |
.find_by_title(title) ⇒ Scrivito::Workspace
Find a workspace by its title. If multiple workspaces share the same title, one of them is returned. If no workspace with the given title can be found, nil is returned.
91 92 93 |
# File 'lib/scrivito/workspace.rb', line 91 def self.find_by_title(title) all.detect { |workspace| workspace.title == title } end |
.reload ⇒ Object
Reloads the current workspace to reflect the changes that were made to it concurrently since it was loaded.
143 144 145 |
# File 'lib/scrivito/workspace.rb', line 143 def self.reload current.reload end |
.use(id_or_title)
This method returns an undefined value.
Find a workspace by its id or title and set it as the currently used workspace.
113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/scrivito/workspace.rb', line 113 def self.use(id_or_title) workspace = begin find(id_or_title) rescue ResourceNotFound find_by_title(id_or_title) end if workspace.blank? raise(ResourceNotFound, "Could not find #{self} with id or title #{id_or_title}") end self.current = workspace end |
Instance Method Details
#destroy ⇒ Object
Destroy this workspace.
189 190 191 192 |
# File 'lib/scrivito/workspace.rb', line 189 def destroy reset_workspace_if_current CmsRestApi.delete(backend_url) end |
#id ⇒ String
Returns the id of the workspace.
215 216 217 |
# File 'lib/scrivito/workspace.rb', line 215 def id @id end |
#memberships ⇒ MembershipCollection
Returns the memberships (users and their roles) of this workspace.
235 236 237 |
# File 'lib/scrivito/workspace.rb', line 235 def memberships @memberships ||= MembershipCollection.new(self) end |
#objs ⇒ ObjCollection
Returns an ObjCollection of this working copy for accessing its CMS objects.
295 296 297 |
# File 'lib/scrivito/workspace.rb', line 295 def objs @objs ||= ObjCollection.new(self) end |
#publish ⇒ Object
Publish the changes that were made to this workspace.
196 197 198 199 200 201 202 |
# File 'lib/scrivito/workspace.rb', line 196 def publish CmsRestApi.put("#{backend_url}/publish", {}) Workspace.published.reload reset_workspace_if_current end |
#rebase ⇒ Object
Rebases the current workspace from the published content in order to integrate the changes that were published in the meantime.
207 208 209 210 |
# File 'lib/scrivito/workspace.rb', line 207 def rebase CmsRestApi.put("#{backend_url}/rebase", {}) reload end |
#reload ⇒ Object
Reloads this workspace to reflect the changes that were made to it concurrently since it was loaded.
159 160 161 |
# File 'lib/scrivito/workspace.rb', line 159 def reload update_data(method(:fetch_workspace_data)) end |
#title ⇒ String
Returns the title of the workspace if present. Otherwise, and for the published content, an empty String is returned.
227 228 229 230 |
# File 'lib/scrivito/workspace.rb', line 227 def title return '' if published? data.title || '' end |
#update(attributes) ⇒ Scrivito::Workspace
Updates the attributes of this workspace.
181 182 183 184 185 |
# File 'lib/scrivito/workspace.rb', line 181 def update(attributes) raise ScrivitoError, 'published workspace is not modifiable' if published? CmsRestApi.put(backend_url, workspace: attributes) reload end |