Sha256: 2d0bf4eb43bb16b2ebf82b11191d0648554b0e3291a0cd88834549f0995a0816
Contents?: true
Size: 1.74 KB
Versions: 3
Compression:
Stored size: 1.74 KB
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 :revision_id data_attr_reader :content_state_id data_attr_reader :base_revision_id data_attr_reader :base_content_state_id data_attr_reader :diff data_attr_reader :uses_obj_classes def content_state @content_state ||= ContentState.find_or_create(content_state_id) if content_state_id end def base_content_state if base_content_state_id @base_content_state ||= ContentState.find_or_create(base_content_state_id) end end 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 create_content_state if content_state_id CmsDataCache.write_workspace_data(id, to_hash) end private def to_hash { 'id' => id, 'revision_id' => revision_id, 'title' => title, 'content_state_id' => content_state_id, 'base_revision_id' => base_revision_id, 'base_content_state_id' => base_content_state_id, 'memberships' => memberships, } end 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
3 entries across 3 versions & 1 rubygems