lib/scrivito/workspace.rb in scrivito_sdk-0.70.2 vs lib/scrivito/workspace.rb in scrivito_sdk-0.71.0.rc1

- old
+ new

@@ -90,38 +90,38 @@ # @return [Scrivito::Workspace] def self.find_by_title(title) all.detect { |workspace| workspace.title == title } end + # # Find a workspace by its id or title and set it as the currently used workspace. - # @example - # Scrivito::Workspace.use('6a75fe694eeeb093') # - # Scrivito::Workspace.current.id - # # => '6a75fe694eeeb093' + # @api public # - # Scrivito::Workspace.use('my working copy') + # @param [String] id_or_title id or title of the workspace + # @raise [Scrivito::ResourceNotFound] + # @return [void] # + # @example + # Scrivito::Workspace.use("6a75fe694eeeb093") + # Scrivito::Workspace.current.id + # # => "6a75fe694eeeb093" + # + # Scrivito::Workspace.use("my working copy") # Scrivito::Workspace.current.title - # # => 'my working copy' + # # => "my working copy" # # # raises Scrivito::ResourceNotFound: - # Scrivito::Workspace.use('missing') - # @api public - # @param [String] id_or_title - # @return [void] - # @raise [Scrivito::ResourceNotFound] + # Scrivito::Workspace.use("missing") + # def self.use(id_or_title) - workspace = begin + self.current = if id_or_title =~ /^[a-z0-9]{16}$/ find(id_or_title) - rescue ResourceNotFound - find_by_title(id_or_title) + else + find_by_title(id_or_title) or + raise ResourceNotFound, "Could not find #{self} with title #{id_or_title}" end - if workspace.blank? - raise(ResourceNotFound, "Could not find #{self} with id or title #{id_or_title}") - end - self.current = workspace end delegate :content_state_id, :base_content_state_id, :content_state, :base_revision_id, :base_content_state, to: :data @@ -168,10 +168,18 @@ response = CmsRestApi.public_send(verb, "#{backend_url}#{path}", payload) reload if [:post, :put, :delete].include?(verb) response end + def create_obj(attributes) + CmsBackend.instance.create_obj(id, attributes).tap { reload } + end + + def update_obj(obj_id, attributes) + CmsBackend.instance.update_obj(id, obj_id, attributes).tap { reload } + end + def task_unaware_api_request(verb, path, payload = nil) CmsRestApi.task_unaware_request(verb, "#{backend_url}#{path}", payload) end # Updates the attributes of this workspace. @@ -229,11 +237,11 @@ data.title || '' end # @api public # Returns the memberships (users and their roles) of this workspace. - # @return [MembershipCollection] + # @return [Scrivito::MembershipCollection] def memberships @memberships ||= MembershipCollection.new(self) end def data @@ -287,13 +295,13 @@ def assert_revertable raise ScrivitoError, 'published workspace is not modifiable' if published? end - # Returns an {ObjCollection} of this working copy for accessing its CMS objects. + # Returns an {Scrivito::ObjCollection} of this working copy for accessing its CMS objects. # @api public - # @return {ObjCollection} + # @return {Scrivito::ObjCollection} def objs @objs ||= ObjCollection.new(self) end def inspect @@ -353,15 +361,16 @@ cache[id] = Workspace.new(data) end def warn_backend_not_available(error_message) - message = <<-EOS + Warning.warn <<-EOS + Couldn't connect to backend to fetch published workspace. #{error_message} Serving from cache. + EOS - Rails.logger.warn(message) end end end end