Class: WorkMetadataService
- Inherits:
-
Object
- Object
- WorkMetadataService
- Defined in:
- app/services/work_metadata_service.rb
Overview
A place to move the logic to from the work controllers
Process the parameters and to update a work
Instance Attribute Summary collapse
-
#current_user ⇒ Object
readonly
Returns the value of attribute current_user.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(params:, current_user:) ⇒ WorkMetadataService
constructor
A new instance of WorkMetadataService.
-
#new_submission ⇒ Object
generates the work for a new submission.
-
#work_for_new_submission ⇒ Object
creates or finds the work for the new submission form based on the parameters.
Constructor Details
#initialize(params:, current_user:) ⇒ WorkMetadataService
Returns a new instance of WorkMetadataService.
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_user ⇒ Object (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 |
#params ⇒ Object (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_submission ⇒ Object
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_submission ⇒ Object
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 |