Sha256: 750d23430859b6612969a107140e23e66c0d8dab57b009b27373ac7add6a90df
Contents?: true
Size: 1.94 KB
Versions: 8
Compression:
Stored size: 1.94 KB
Contents
module Scrivito class WorkspaceDataFromService class << self # Fetches a workspace data previously store in cache storage. # Returns nil if not found. def find_from_cache(id) if data = CmsCacheStorage.read_workspace_data(id) new(data) end end private def data_attr_reader(attr_name) define_method(attr_name) { @data[attr_name.to_s] } end end data_attr_reader :id data_attr_reader :title 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 :memberships def initialize(data) @data = data end 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 CmsCacheStorage.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
8 entries across 8 versions & 1 rubygems