module RailsConnector # @api public module Migrations # @api public module MigrationDsl # Creates a CMS attribute. # # @example Create "test" Attribute # # create_attribute(:name => 'test', :type => 'string') # # @param attributes [Hash] The attributes and their values of the new # CMS attribute. # # @return nothing # @deprecated Please use local attributes. Create attributes using {#create_obj_class} or # {#update_obj_class}. # @api public def create_attribute(attributes = {}) warn_deprecated __callee__, 'create_obj_class', 'update_obj_class' endpoint = "revisions/#{Workspace.current.revision_id}/attributes" CmsRestApi.post(endpoint, :attribute => attributes) end # Creates a CMS object. # # @example Create "/test" Object # # create_obj(:_path => '/test', :_obj_class => 'Test') # # @param attributes [Hash] The attributes and their values of the new # CMS object. # # @return nothing # @api public def create_obj(attributes = {}) endpoint = "revisions/#{Workspace.current.revision_id}/objs" CmsRestApi.post(endpoint, :obj => attributes) end # Creates a CMS object class. # # @example Create "Test" Object Class # # create_obj_class(:name => 'Test', :type => 'publication') # # @param attributes [Hash] The attributes and their values of the new # CMS object class. # # @return nothing # @api public def create_obj_class(attributes = {}) endpoint = "revisions/#{Workspace.current.revision_id}/obj_classes" CmsRestApi.post(endpoint, :obj_class => attributes) end # Deletes a CMS attribute. # # @example Delete "test" Attribute # # delete_attribute('test') # # @param id [String] The ID of the CMS attribute. # # @return nothing # @deprecated Please use local attributes. Delete attributes using {#update_obj_class}. # @api public def delete_attribute(id) warn_deprecated __callee__, 'update_obj_class' endpoint = "revisions/#{Workspace.current.revision_id}/attributes/#{id}" CmsRestApi.delete(endpoint) end # Deletes a CMS object with the given id. # # @example Deletes "a1b2c3" Object # # delete_obj('a1b2c3') # # @param id [String] The ID of the CMS object. # # @return nothing # @api public def delete_obj(id) endpoint = "revisions/#{Workspace.current.revision_id}/objs/#{id}" CmsRestApi.delete(endpoint) end # Fetches all attribute attributes and their values. # # @example Get all attributes for the attribute "test" # # get_attribute('test') # # @param id [String] The ID of the attribute. # # @return [Hash] a hash with attributes and their values. # @deprecated Please use local attributes. Get attributes using {#get_obj_class}. # @api public def get_attribute(id) warn_deprecated __callee__, 'get_obj_class' endpoint = "revisions/#{Workspace.current.revision_id}/attributes/#{id}" CmsRestApi.get(endpoint) end # Fetches all object attributes and their values. # # @example Get all attributes for the obj with id "abc123" # # get_obj('abc123') # # @param id [String] The ID of the CMS object. # # @return [Hash] a hash with attributes and their values. # @api public def get_obj(id) endpoint = "revisions/#{Workspace.current.revision_id}/objs/#{id}" CmsRestApi.get(endpoint) end # Fetches all object class attributes and their values. # # @example Get all attributes for the object class "Test" # # get_obj_class('Test') # # @param id [String] The ID of the object class. # # @return [Hash] a hash with attributes and their values. # @api public def get_obj_class(id) endpoint = "revisions/#{Workspace.current.revision_id}/obj_classes/#{id}" CmsRestApi.get(endpoint) end # Updates a CMS attribute. # # @example Update the title of the "test" Attribute # # update_attribute(:title => 'Test Title') # # @param id [String] The ID of the attribute. # @param attributes [Hash] The updated attributes and their values. # # @return nothing # @deprecated Please use local attributes. Update attributes using {#update_obj_class}. # @api public def update_attribute(id, attributes = {}) warn_deprecated __callee__, 'update_obj_class' endpoint = "revisions/#{Workspace.current.revision_id}/attributes/#{id}" CmsRestApi.put(endpoint, :attribute => attributes) end # Updates a CMS object. # # @example Update the title of the "a1b2c3" Object # # update_attribute('a1b2c3', :title => 'Test Title') # # @param id [String] The ID of the CMS object. # @param attributes [Hash] The updated attributes and their values. # # @return nothing # @api public def update_obj(id, attributes = {}) endpoint = "revisions/#{Workspace.current.revision_id}/objs/#{id}" CmsRestApi.put(endpoint, :obj => attributes) end # Updates a CMS object class. # # @example Update the title of the "Test" Object Class # # update_obj_class('Test', :title => 'Test Title') # # @param id [String] The ID of the CMS object class. # @param attributes [Hash] The updated attributes and their values. # # @return nothing # @api public def update_obj_class(id, attributes = {}) endpoint = "revisions/#{Workspace.current.revision_id}/obj_classes/#{id}" CmsRestApi.put(endpoint, :obj_class => attributes) end private def warn_deprecated(method, *substitutes) warn "[DEPRECATION] '#{method}' is deprecated. Use '#{substitutes.join("' or '")}' instead." end end end end