Class: RailsConnector::Workspace

Inherits:
Object
  • Object
show all
Extended by:
ActiveModel::Naming
Defined in:
lib/rails_connector/workspace.rb

Overview

This class represents a CMS workspace

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.allArray<RailsConnector::Workspace>

Returns all the workspaces

Returns:


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

Parameters:

  • attributes (Hash)

Returns:


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

.currentRailsConnector::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

Parameters:


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

Parameters:

  • id (String)

Returns:

Raises:


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

.reloadObject

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

#destroyObject

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

#idString

Returns the id of the workspace

Returns:

  • (String)

129
130
131
# File 'lib/rails_connector/workspace.rb', line 129

def id
  @workspace_data.id
end

#publishObject

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

#rebaseObject

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

#reloadObject

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

#titleString

Returns the title of the workspace

Returns:

  • (String)

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

Parameters:

  • attributes (Hash)

Returns:


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