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
Class Method Summary collapse
-
.all ⇒ Array<Scrivito::Workspace>
Returns all the workspaces.
-
.create(attributes) ⇒ Scrivito::Workspace
Create a new workspace.
-
.current ⇒ Scrivito::Workspace
Returns the currently used workspace.
-
.current=(workspace) ⇒ Object
Set the currently used workspace.
-
.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 any changes to it that may have happened concurrently since it was loaded.
Instance Method Summary collapse
-
#destroy ⇒ Object
Destroy this workspace.
-
#id ⇒ String
Returns the id of the workspace.
-
#memberships ⇒ MembershipCollection
Returns the members of this workspace and their roles.
- #obj_classes ⇒ ObjClassCollection deprecated Deprecated.
-
#objs ⇒ ObjCollection
ObjCollection for this working copy.
-
#publish ⇒ Object
Publish the changes of this workspace.
-
#rebase ⇒ Object
Rebases the current workspace on the published content.
-
#reload ⇒ Object
Reloads this workspace to reflect any changes to it that may have happened concurrently since it was loaded.
-
#title ⇒ String
Returns the title of the workspace.
-
#update(attributes) ⇒ Scrivito::Workspace
Updates this workspace’s attributes.
Class Method Details
.all ⇒ Array<Scrivito::Workspace>
Returns all the workspaces
41 42 43 44 45 46 47 |
# File 'lib/scrivito/workspace.rb', line 41 def self.all result_json = CmsRestApi.get('/workspaces') result_json['results'].map do |workspace_json| Workspace.find(workspace_json['id']) end end |
.create(attributes) ⇒ Scrivito::Workspace
Create a new workspace
88 89 90 91 92 |
# File 'lib/scrivito/workspace.rb', line 88 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
30 31 32 33 34 35 36 |
# File 'lib/scrivito/workspace.rb', line 30 def self.current if @current.respond_to? :call @current = @current.call else @current ||= default end end |
.current=(workspace) ⇒ Object
Set the currently used workspace
19 20 21 |
# File 'lib/scrivito/workspace.rb', line 19 def self.current=(workspace) @current = workspace end |
.find(id) ⇒ Scrivito::Workspace
Find a workspace by its id
64 65 66 67 68 69 70 |
# File 'lib/scrivito/workspace.rb', line 64 def self.find(id) if workspace_data = CmsBackend.instance.find_workspace_data_by_id(id) Workspace.new workspace_data else raise ResourceNotFound, "Could not find #{self} with id #{id}" 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.
78 79 80 |
# File 'lib/scrivito/workspace.rb', line 78 def self.find_by_title(title) all.detect { |workspace| workspace.title == title } end |
.reload ⇒ Object
reloads the current workspace to reflect any changes to it that may have happened concurrently since it was loaded
97 98 99 100 |
# File 'lib/scrivito/workspace.rb', line 97 def self.reload id = current.id self.current_using_proc = proc { find(id) } end |
Instance Method Details
#destroy ⇒ Object
Destroy this workspace
143 144 145 146 |
# File 'lib/scrivito/workspace.rb', line 143 def destroy reset_workspace_if_current CmsRestApi.delete(backend_url) end |
#id ⇒ String
Returns the id of the workspace
166 167 168 |
# File 'lib/scrivito/workspace.rb', line 166 def id @workspace_data.id end |
#memberships ⇒ MembershipCollection
Returns the members of this workspace and their roles
185 186 187 |
# File 'lib/scrivito/workspace.rb', line 185 def memberships @memberships ||= MembershipCollection.new(self) end |
#obj_classes ⇒ ObjClassCollection
Returns all obj classes of this working copy.
253 254 255 |
# File 'lib/scrivito/workspace.rb', line 253 def obj_classes @obj_classes ||= ObjClassCollection.new(self) end |
#objs ⇒ ObjCollection
ObjCollection for this working copy
240 241 242 |
# File 'lib/scrivito/workspace.rb', line 240 def objs @objs ||= ObjCollection.new(self) end |
#publish ⇒ Object
Publish the changes of this workspace
150 151 152 153 154 |
# File 'lib/scrivito/workspace.rb', line 150 def publish CmsRestApi.put("#{backend_url}/publish", {}) reset_workspace_if_current end |
#rebase ⇒ Object
Rebases the current workspace on the published content
158 159 160 161 |
# File 'lib/scrivito/workspace.rb', line 158 def rebase CmsRestApi.put("#{backend_url}/rebase", {}) reload end |
#reload ⇒ Object
Reloads this workspace to reflect any changes to it that may have happened concurrently since it was loaded
113 114 115 116 117 118 119 120 |
# File 'lib/scrivito/workspace.rb', line 113 def reload @workspace_data = CmsBackend.instance.find_workspace_data_by_id(self.id) # Clear all cached instance variables. @base_revision = nil @memberships = nil @revision = nil end |
#title ⇒ String
Returns the title of the workspace
177 178 179 |
# File 'lib/scrivito/workspace.rb', line 177 def title @workspace_data.title end |
#update(attributes) ⇒ Scrivito::Workspace
Updates this workspace’s attributes
136 137 138 139 |
# File 'lib/scrivito/workspace.rb', line 136 def update(attributes) CmsRestApi.put(backend_url, workspace: attributes) reload end |