Sha256: 1f7cd6c9225b4e751e5cc61da4b6cad50ea5e0b0bb296f28da3f931231713c41

Contents?: true

Size: 1.04 KB

Versions: 2

Compression:

Stored size: 1.04 KB

Contents

module RailsConnector

class Workspace
  extend ActiveModel::Naming

  include ModelIdentity

  def self.current=(workspace_or_proc)
    @current = workspace_or_proc
  end

  def self.current
    if @current.respond_to? :call
      @current = @current.call
    else
      @current || default
    end
  end

  def self.default
    find("published")
  end

  def self.find(id)
    if workspace_data = CmsBackend.find_workspace_data_by_id(id)
      Workspace.new workspace_data
    else
      raise ResourceNotFound, "Could not find #{self} with id #{id}"
    end
  end

  def initialize(workspace_data)
    @workspace_data = workspace_data
  end

  def id
    @workspace_data.id
  end

  def revision_id
    @workspace_data.revision_id
  end

  def title
    @workspace_data.title
  end

  def data
    @workspace_data
  end

  def published?
    self.id == 'published'
  end

  def as_current(&block)
    old_workspace = Workspace.current

    begin
      Workspace.current = self

      yield
    ensure
      Workspace.current = old_workspace
    end
  end

end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
infopark_cloud_connector-6.9.1.3.22208381 lib/rails_connector/workspace.rb
infopark_cloud_connector-6.9.0.3.197272233 lib/rails_connector/workspace.rb