Module: RailsConnector::Migrations::MigrationDsl

Defined in:
lib/rails_connector/migrations/migration_dsl.rb

Instance Method Summary collapse

Instance Method Details

#create_attribute(attributes = {}) ⇒ Object

Deprecated.

Please use local attributes. Create attributes using #create_obj_class or #update_obj_class.

Creates a CMS attribute.

Examples:

Create “test” Attribute


create_attribute(name: 'test', type: 'string')

Parameters:

  • attributes (Hash) (defaults to: {})

    The attributes and their values of the new CMS attribute.

Returns:

  • nothing



19
20
21
22
23
24
# File 'lib/rails_connector/migrations/migration_dsl.rb', line 19

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

#create_obj(attributes = {}) ⇒ Object

Creates a CMS object.

Examples:

Create “/test” Object


create_obj(_path: '/test', _obj_class: 'Test')

Parameters:

  • attributes (Hash) (defaults to: {})

    The attributes and their values of the new CMS object.

Returns:

  • nothing



117
118
119
120
121
# File 'lib/rails_connector/migrations/migration_dsl.rb', line 117

def create_obj(attributes = {})
  endpoint = "revisions/#{Workspace.current.revision_id}/objs"

  CmsRestApi.post(endpoint, obj: attributes)
end

#create_obj_class(attributes = {}) ⇒ Object

Creates a CMS object class.

Examples:

Create “Test” Object Class


create_obj_class(name: 'Test', type: 'publication')

Parameters:

  • attributes (Hash) (defaults to: {})

    The attributes and their values of the new CMS object class.

Returns:

  • nothing



134
135
136
137
138
# File 'lib/rails_connector/migrations/migration_dsl.rb', line 134

def create_obj_class(attributes = {})
  endpoint = "revisions/#{Workspace.current.revision_id}/obj_classes"

  CmsRestApi.post(endpoint, obj_class: attributes)
end

#delete_attribute(id) ⇒ Object

Deprecated.

Please use local attributes. Delete attributes using #update_obj_class.

Deletes a CMS attribute.

Examples:

Delete “test” Attribute


delete_attribute('test')

Parameters:

  • id (String)

    The ID of the CMS attribute.

Returns:

  • nothing



151
152
153
154
155
156
# File 'lib/rails_connector/migrations/migration_dsl.rb', line 151

def delete_attribute(id)
  warn_deprecated __callee__, 'update_obj_class'
  endpoint = "revisions/#{Workspace.current.revision_id}/attributes/#{id}"

  CmsRestApi.delete(endpoint)
end

#delete_obj(id) ⇒ Object

Deletes a CMS object with the given id.

Examples:

Deletes “a1b2c3” Object


delete_obj('a1b2c3')

Parameters:

  • id (String)

    The ID of the CMS object.

Returns:

  • nothing



168
169
170
171
172
# File 'lib/rails_connector/migrations/migration_dsl.rb', line 168

def delete_obj(id)
  endpoint = "revisions/#{Workspace.current.revision_id}/objs/#{id}"

  CmsRestApi.delete(endpoint)
end

#get_attribute(id) ⇒ Hash

Deprecated.

Please use local attributes. Get attributes using #get_obj_class.

Fetches all attribute attributes and their values.

Examples:

Get all attributes for the attribute “test”


get_attribute('test')

Parameters:

  • id (String)

    The ID of the attribute.

Returns:

  • (Hash)

    a hash with attributes and their values.



185
186
187
188
189
190
# File 'lib/rails_connector/migrations/migration_dsl.rb', line 185

def get_attribute(id)
  warn_deprecated __callee__, 'get_obj_class'
  endpoint = "revisions/#{Workspace.current.revision_id}/attributes/#{id}"

  CmsRestApi.get(endpoint)
end

#get_obj(id) ⇒ Hash

Fetches all object attributes and their values.

Examples:

Get all attributes for the obj with id “abc123”


get_obj('abc123')

Parameters:

  • id (String)

    The ID of the CMS object.

Returns:

  • (Hash)

    a hash with attributes and their values.



202
203
204
205
206
# File 'lib/rails_connector/migrations/migration_dsl.rb', line 202

def get_obj(id)
  endpoint = "revisions/#{Workspace.current.revision_id}/objs/#{id}"

  CmsRestApi.get(endpoint)
end

#get_obj_class(id) ⇒ Hash

Fetches all object class attributes and their values.

Examples:

Get all attributes for the object class “Test”


get_obj_class('Test')

Parameters:

  • id (String)

    The ID of the object class.

Returns:

  • (Hash)

    a hash with attributes and their values.



218
219
220
221
222
# File 'lib/rails_connector/migrations/migration_dsl.rb', line 218

def get_obj_class(id)
  endpoint = "revisions/#{Workspace.current.revision_id}/obj_classes/#{id}"

  CmsRestApi.get(endpoint)
end

#update_attribute(id, attributes = {}) ⇒ Object

Deprecated.

Please use local attributes. Update attributes using #update_obj_class.

Updates a CMS attribute.

Examples:

Update the title of the “test” Attribute


update_attribute(title: 'Test Title')

Parameters:

  • id (String)

    The ID of the attribute.

  • attributes (Hash) (defaults to: {})

    The updated attributes and their values.

Returns:

  • nothing



236
237
238
239
240
241
# File 'lib/rails_connector/migrations/migration_dsl.rb', line 236

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

#update_obj(id, attributes = {}) ⇒ Object

Updates a CMS object.

Examples:

Update the title of the “a1b2c3” Object


update_attribute('a1b2c3', title: 'Test Title')

Parameters:

  • id (String)

    The ID of the CMS object.

  • attributes (Hash) (defaults to: {})

    The updated attributes and their values.

Returns:

  • nothing



254
255
256
257
258
# File 'lib/rails_connector/migrations/migration_dsl.rb', line 254

def update_obj(id, attributes = {})
  endpoint = "revisions/#{Workspace.current.revision_id}/objs/#{id}"

  CmsRestApi.put(endpoint, obj: attributes)
end

#update_obj_class(id, attributes = {}) ⇒ Object

Updates a CMS object class.

Examples:

Update the title of the “Test” Object Class


update_obj_class('Test', title: 'Test Title')

Parameters:

  • id (String)

    The ID of the CMS object class.

  • attributes (Hash) (defaults to: {})

    The updated attributes and their values.

Returns:

  • nothing



271
272
273
274
275
# File 'lib/rails_connector/migrations/migration_dsl.rb', line 271

def update_obj_class(id, attributes = {})
  endpoint = "revisions/#{Workspace.current.revision_id}/obj_classes/#{id}"

  CmsRestApi.put(endpoint, obj_class: attributes)
end

#upload_file(file) ⇒ Object

Uploads a file to the content store.

Examples:

Upload “image.png” and store it in an “Image” CMS object.


filename = 'image.png'
file = File.new(filename)
blob = upload_file(file)
create_obj(_path: "/resources/images/#{filename}", _obj_class: 'Image', blob: blob)

Parameters:

  • file (IO)

    The file IO object that gets uploaded.

Returns:

  • The blob of the uploaded file that can be stored on a CMS object.



290
291
292
293
294
295
296
297
298
299
# File 'lib/rails_connector/migrations/migration_dsl.rb', line 290

def upload_file(file)
  upload_permission = RailsConnector::CmsRestApi.get('blobs/upload_permission')

  fields = upload_permission['fields'].map { |name, value| [name, value] }
  fields << [:file, file]

  RestClient.post(upload_permission['url'], fields)

  upload_permission['blob']
end