Class: RailsConnector::Workspace
- Inherits:
-
Object
- Object
- RailsConnector::Workspace
- Extended by:
- ActiveModel::Naming
- Defined in:
- lib/rails_connector/workspace.rb
Overview
This class represents a CMS workspace
Class Method Summary collapse
-
.all ⇒ Array<RailsConnector::Workspace>
Returns all the workspaces.
-
.create(attributes) ⇒ RailsConnector::Workspace
Create a new workspace.
-
.current ⇒ RailsConnector::Workspace
Returns the currently used workspace.
-
.current=(workspace) ⇒ Object
Set the currently used workspace.
-
.find(id) ⇒ RailsConnector::Workspace
Find a workspace by its id.
-
.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.
-
#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) ⇒ RailsConnector::Workspace
Updates this workspace’s attributes.
Class Method Details
.all ⇒ Array<RailsConnector::Workspace>
Returns all the workspaces
35 36 37 38 39 40 41 |
# File 'lib/rails_connector/workspace.rb', line 35 def self.all result_json = CmsRestApi.get('/workspaces') result_json['results'].map do |workspace_json| Workspace.find(workspace_json['id']) end end |
.create(attributes) ⇒ RailsConnector::Workspace
Create a new workspace
66 67 68 69 70 |
# File 'lib/rails_connector/workspace.rb', line 66 def self.create(attributes) workspace_json = CmsRestApi.post("/workspaces", workspace: attributes) self.find(workspace_json["id"]) end |
.current ⇒ RailsConnector::Workspace
Returns the currently used workspace
24 25 26 27 28 29 30 |
# File 'lib/rails_connector/workspace.rb', line 24 def self.current if @current.respond_to? :call @current = @current.call else @current ||= default end end |
.current=(workspace) ⇒ Object
Set the currently used workspace
13 14 15 |
# File 'lib/rails_connector/workspace.rb', line 13 def self.current=(workspace) @current = workspace end |
.find(id) ⇒ RailsConnector::Workspace
Find a workspace by its id
52 53 54 55 56 57 58 |
# File 'lib/rails_connector/workspace.rb', line 52 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 |
.reload ⇒ Object
reloads the current workspace to reflect any changes to it that may have happened concurrently since it was loaded
75 76 77 78 |
# File 'lib/rails_connector/workspace.rb', line 75 def self.reload id = current.id self.current_using_proc = proc { find(id) } end |
Instance Method Details
#destroy ⇒ Object
Destroy this workspace
104 105 106 107 108 |
# File 'lib/rails_connector/workspace.rb', line 104 def destroy CmsRestApi.delete(backend_url) reset_workspace_if_current end |
#id ⇒ String
Returns the id of the workspace
129 130 131 |
# File 'lib/rails_connector/workspace.rb', line 129 def id @workspace_data.id end |
#publish ⇒ Object
Publish the changes of this workspace
112 113 114 115 116 |
# File 'lib/rails_connector/workspace.rb', line 112 def publish CmsRestApi.put("#{backend_url}/publish", {}) reset_workspace_if_current end |
#rebase ⇒ Object
Rebases the current workspace on the published content
120 121 122 123 124 |
# File 'lib/rails_connector/workspace.rb', line 120 def rebase CmsRestApi.put("#{backend_url}/rebase", {}) self.reload end |
#reload ⇒ Object
Reloads this workspace to reflect any changes to it that may have happened concurrently since it was loaded
87 88 89 90 |
# File 'lib/rails_connector/workspace.rb', line 87 def reload @workspace_data = CmsBackend.instance.find_workspace_data_by_id(self.id) @revision = @base_revision = nil end |
#title ⇒ String
Returns the title of the workspace
140 141 142 |
# File 'lib/rails_connector/workspace.rb', line 140 def title @workspace_data.title end |
#update(attributes) ⇒ RailsConnector::Workspace
Updates this workspace’s attributes
96 97 98 99 100 |
# File 'lib/rails_connector/workspace.rb', line 96 def update(attributes) CmsRestApi.put(backend_url, workspace: attributes) self.reload end |