Class: WorkMetadataService

Inherits:
Object
  • Object
show all
Defined in:
app/services/work_metadata_service.rb

Overview

A place to move the logic to from the work controllers

Process the parameters and permissions to update a work

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params:, current_user:) ⇒ WorkMetadataService

Returns a new instance of WorkMetadataService.

Parameters:

  • update_params (HashWithIndifferentAccess)

    values to update the work with



10
11
12
13
# File 'app/services/work_metadata_service.rb', line 10

def initialize(params:, current_user:)
  @params = params
  @current_user = current_user
end

Instance Attribute Details

#current_userObject (readonly)

Returns the value of attribute current_user.



6
7
8
# File 'app/services/work_metadata_service.rb', line 6

def current_user
  @current_user
end

#paramsObject (readonly)

Returns the value of attribute params.



6
7
8
# File 'app/services/work_metadata_service.rb', line 6

def params
  @params
end

Class Method Details

.file_location_url(work) ⇒ Object



38
39
40
41
42
43
44
# File 'app/services/work_metadata_service.rb', line 38

def self.file_location_url(work)
  if work.files_location == "file_upload"
    Rails.application.routes.url_helpers.work_file_upload_path(work)
  else
    Rails.application.routes.url_helpers.work_file_other_path(work)
  end
end

Instance Method Details

#new_submissionObject

generates the work for a new submission



29
30
31
32
33
34
35
36
# File 'app/services/work_metadata_service.rb', line 29

def new_submission
  work = work_for_new_submission
  work.resource = FormToResourceService.convert(params, work)
  if work.valid_to_draft
    work.draft!(current_user)
  end
  work
end

#work_for_new_submissionObject

creates or finds the work for the new submission form based on the parameters



18
19
20
21
22
23
24
# File 'app/services/work_metadata_service.rb', line 18

def work_for_new_submission
  if params[:id].present?
    Work.find(params[:id])
  else
    Work.new(created_by_user_id: current_user.id, group_id: group_code.id)
  end
end