Sha256: b266a09e44c806fc52e23bbc1b89d9904e90ef344df85abe600363655280d2dd

Contents?: true

Size: 968 Bytes

Versions: 23

Compression:

Stored size: 968 Bytes

Contents

module Scrivito

class WorkspaceDataFromService < WorkspaceData
  class << self
    # Fetches a workspace data previously store in cache storage.
    # Returns nil if not found.
    def find_from_cache(id)
      if data = CmsDataCache.read_workspace_data(id)
        new(data)
      end
    end
  end

  data_attr_reader :diff

  def changes
    diff && diff['changes']
  end

  def from_content_state_id
    diff && diff['from_content_state_id']
  end

  def to_content_state_id
    diff && diff['to_content_state_id']
  end

  # Serializes and stores a workspace data in cache storage.
  # Also creates an appropriate content state if needed.
  def store_in_cache_and_create_content_state
    create_content_state if content_state_id
    store_in_cache
  end

  private

  def create_content_state
    ContentState.create(content_state_id: to_content_state_id, changes: changes,
        from_content_state_id: from_content_state_id)
  end
end

end # module Scrivito

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
scrivito_sdk-0.66.0 lib/scrivito/workspace_data_from_service.rb
scrivito_sdk-0.66.0.rc2 lib/scrivito/workspace_data_from_service.rb
scrivito_sdk-0.66.0.rc1 lib/scrivito/workspace_data_from_service.rb