module RailsConnector class WorkspaceDataFromService # Fetches a workspace data previously store in cache storage. # Returns nil if not found. def self.find_from_cache(id) if data = CmsCacheStorage.read_workspace_data(id) new(data) end end def initialize(data) @data = data end def revision_id @data["revision_id"] end def id @data["id"] end def title @data["title"] end # remove this method after DynamoCmsBackend has been removed from the Cloud Connector def content_cache_id=(id) # ignore, since not using content caches end def content_state_id @data['content_state_id'] end def content_state @content_state ||= ContentState.find_or_create(content_state_id) if content_state_id end def diff @data['diff'] 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, } 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 RailsConnector