lib/scrivito/migrations/migration_dsl.rb in scrivito_sdk-0.16.0 vs lib/scrivito/migrations/migration_dsl.rb in scrivito_sdk-0.17.0

- old
+ new

@@ -3,47 +3,63 @@ module Migrations # @api public module MigrationDsl # Adds an attribute to an object class. # + # @deprecated Please use {AttributeCollection#add} instead. + # # @example Add "test" attribute to object class "Foo. # # add_attribute_to('Foo', { name: 'test', type: 'string' }) # # @param obj_class_name [String] The class name of the object class. # @param params [Hash] The definition of the new attribute. # # @return nothing def add_attribute_to(obj_class_name, params) + Deprecation.warn_method( + 'add_attribute_to', + 'ObjClass#attributes.add(Attribute.new(params))' + ) + attributes = get_obj_class(obj_class_name)['attributes'] attributes << params update_obj_class(obj_class_name, attributes: attributes) end # Deletes an attribute from an object class. # + # @deprecated Please use {Attribute#destroy} instead. + # # @example Delete "test" attribute from object class "Foo. # # delete_attribute_from('Foo', 'test') # # @param obj_class_name [String] The class name of the object class. # @param attribute_name [String] The name of the attribute that should be # deleted. # # @return nothing def delete_attribute_from(obj_class_name, attribute_name) + Deprecation.warn_method( + 'delete_attribute_from', + 'ObjClass#attributes[attribute_name].destroy()' + ) + attributes = get_obj_class(obj_class_name)['attributes'] attributes = attributes.delete_if do |attribute| attribute['name'] == attribute_name.to_s end update_obj_class(obj_class_name, attributes: attributes) end # Updates an attribute for an object class. # + # @deprecated Please use {Attribute#update} instead. + # # @example Update "test" attribute for object class "Foo. # # update_attribute_for('Foo', 'test', { title: 'New Title' }) # # @param obj_class_name [String] The class name of the object class. @@ -51,10 +67,15 @@ # updated. # @param params [Hash] Hash of updated attributes. # # @return nothing def update_attribute_for(obj_class_name, attribute_name, params) + Deprecation.warn_method( + 'update_attribute_for', + 'ObjClass#attributes[attribute_name].update(params)' + ) + attribute_name = attribute_name.to_s attributes = get_obj_class(obj_class_name)['attributes'] found = false attributes.each_with_index do |attribute, index| @@ -73,68 +94,84 @@ end end # Creates a CMS object class. # + # @deprecated Please use {ObjClass.create} instead. + # # @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 = {}) + Deprecation.warn_method('create_obj_class', 'ObjClass.create(attributes)') + endpoint = "workspaces/#{Workspace.current.id}/obj_classes" CmsRestApi.post(endpoint, obj_class: attributes) end # Fetches all object attributes and their values. # + # @deprecated Please use {BasicObj.find} instead. + # # @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) + Deprecation.warn_method('get_obj', 'Obj.find(id)') + endpoint = "workspaces/#{Workspace.current.id}/objs/#{id}" CmsRestApi.get(endpoint) end # Fetches all object class attributes and their values. # + # @deprecated Please use {ObjClass.find} instead. + # # @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) + Deprecation.warn_method('get_obj_class', 'ObjClass.find(id)') + endpoint = "workspaces/#{Workspace.current.id}/obj_classes/#{id}" CmsRestApi.get(endpoint) end # Updates a CMS object class. # + # @deprecated Please use {ObjClass#update} instead. + # # @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 = {}) + Deprecation.warn_method('update_obj_class', 'ObjClass#update(attributes)') + endpoint = "workspaces/#{Workspace.current.id}/obj_classes/#{id}" CmsRestApi.put(endpoint, obj_class: attributes) end end