Module: RailsConnector::Migrations::MigrationDsl

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

Instance Method Summary collapse

Instance Method Details

#create_obj(attributes = {}) ⇒ Object

Deprecated.

use Obj.create instead

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


89
90
91
92
93
94
95
# File 'lib/rails_connector/migrations/migration_dsl.rb', line 89

def create_obj(attributes = {})
  Deprecation.warn_method('create_obj', 'Obj.create')

  endpoint = "workspaces/#{Workspace.current.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


108
109
110
111
112
# File 'lib/rails_connector/migrations/migration_dsl.rb', line 108

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

  CmsRestApi.post(endpoint, obj_class: attributes)
end

#delete_obj(id) ⇒ Object

Deprecated.

use Obj#destroy instead

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


126
127
128
129
130
131
132
# File 'lib/rails_connector/migrations/migration_dsl.rb', line 126

def delete_obj(id)
  Deprecation.warn_method('delete_obj', 'Obj#destroy')

  endpoint = "workspaces/#{Workspace.current.id}/objs/#{id}"

  CmsRestApi.delete(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.


144
145
146
147
148
# File 'lib/rails_connector/migrations/migration_dsl.rb', line 144

def get_obj(id)
  endpoint = "workspaces/#{Workspace.current.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.


160
161
162
163
164
# File 'lib/rails_connector/migrations/migration_dsl.rb', line 160

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

  CmsRestApi.get(endpoint)
end

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

Deprecated.

use Obj#update instead

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


179
180
181
182
183
184
# File 'lib/rails_connector/migrations/migration_dsl.rb', line 179

def update_obj(id, attributes = {})
  Deprecation.warn_method('update_obj', 'Obj#update')
  endpoint = "workspaces/#{Workspace.current.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


197
198
199
200
201
# File 'lib/rails_connector/migrations/migration_dsl.rb', line 197

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

  CmsRestApi.put(endpoint, obj_class: attributes)
end

#upload_file(file) ⇒ Object

Deprecated.

use Obj.create or Obj#update instead

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.


217
218
219
220
221
222
223
224
225
226
227
# File 'lib/rails_connector/migrations/migration_dsl.rb', line 217

def upload_file(file)
  Deprecation.warn_method("upload_file", "Obj.create or Obj#update")
  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