Class: Hyrax::Action::CreateValkyrieWork
- Inherits:
-
Object
- Object
- Hyrax::Action::CreateValkyrieWork
- Defined in:
- app/services/hyrax/action/create_valkyrie_work.rb
Overview
Encapsulating the logic of several interacting objects. Namely the idea of using a form to #validate given parameters then to #perform the action by leveraging the #transactions‘s #transaction_name configured with appropriate #step_args and ultimately providing the #form to then perform that work.
Class Attributes collapse
-
#transaction_name ⇒ String
The name of the transaction that we call for the CreateValkyrieWorkAction.
Instance Attribute Summary collapse
- #form ⇒ Object readonly
- #params ⇒ Object readonly
- #parent_id ⇒ Object readonly
- #transactions ⇒ Object readonly
-
#uploaded_files ⇒ Object
readonly
rubocop:disable Lint/DuplicateMethods.
- #user ⇒ Object readonly
- #work_attributes ⇒ Object readonly
- #work_attributes_key ⇒ Object readonly
Instance Method Summary collapse
-
#initialize(form:, transactions:, user:, params:, work_attributes_key:) ⇒ CreateValkyrieWork
constructor
A new instance of CreateValkyrieWork.
-
#perform ⇒ #value_or
The resulting created work, when successful.
-
#step_args ⇒ Hash<String,Hash>
The step args to use for the given #transactions‘s #transaction_name.
- #validate ⇒ TrueClass, FalseClass
Constructor Details
#initialize(form:, transactions:, user:, params:, work_attributes_key:) ⇒ CreateValkyrieWork
Returns a new instance of CreateValkyrieWork.
31 32 33 34 35 36 37 38 |
# File 'app/services/hyrax/action/create_valkyrie_work.rb', line 31 def initialize(form:, transactions:, user:, params:, work_attributes_key:) @form = form @transactions = transactions @user = user @params = params @work_attributes_key = work_attributes_key @work_attributes = @params.fetch(work_attributes_key, {}) end |
Instance Attribute Details
#form ⇒ Object (readonly)
40 41 42 |
# File 'app/services/hyrax/action/create_valkyrie_work.rb', line 40 def form @form end |
#params ⇒ Object (readonly)
40 41 42 |
# File 'app/services/hyrax/action/create_valkyrie_work.rb', line 40 def params @params end |
#parent_id ⇒ Object (readonly)
40 41 42 |
# File 'app/services/hyrax/action/create_valkyrie_work.rb', line 40 def parent_id @parent_id end |
#transaction_name ⇒ String
Returns the name of the transaction that we call for the CreateValkyrieWorkAction.
19 |
# File 'app/services/hyrax/action/create_valkyrie_work.rb', line 19 class_attribute :transaction_name, default: 'change_set.create_work' |
#transactions ⇒ Object (readonly)
40 41 42 |
# File 'app/services/hyrax/action/create_valkyrie_work.rb', line 40 def transactions @transactions end |
#uploaded_files ⇒ Object (readonly)
rubocop:disable Lint/DuplicateMethods
74 75 76 |
# File 'app/services/hyrax/action/create_valkyrie_work.rb', line 74 def uploaded_files @uploaded_files end |
#user ⇒ Object (readonly)
40 41 42 |
# File 'app/services/hyrax/action/create_valkyrie_work.rb', line 40 def user @user end |
#work_attributes ⇒ Object (readonly)
40 41 42 |
# File 'app/services/hyrax/action/create_valkyrie_work.rb', line 40 def work_attributes @work_attributes end |
#work_attributes_key ⇒ Object (readonly)
40 41 42 |
# File 'app/services/hyrax/action/create_valkyrie_work.rb', line 40 def work_attributes_key @work_attributes_key end |
Instance Method Details
#perform ⇒ #value_or
The resulting created work, when successful. When not successful, the returned value call the given block.
54 55 56 |
# File 'app/services/hyrax/action/create_valkyrie_work.rb', line 54 def perform transactions[transaction_name].with_step_args(**step_args).call(form) end |
#step_args ⇒ Hash<String,Hash>
Returns the step args to use for the given #transactions‘s #transaction_name.
63 64 65 66 67 68 69 70 71 |
# File 'app/services/hyrax/action/create_valkyrie_work.rb', line 63 def step_args { 'work_resource.add_to_parent' => { parent_id: params[:parent_id], user: user }, 'work_resource.add_file_sets' => { uploaded_files: uploaded_files, file_set_params: work_attributes[:file_set] }, 'change_set.set_user_as_depositor' => { user: user }, 'work_resource.change_depositor' => { user: ::User.find_by_user_key(form.on_behalf_of) }, 'work_resource.save_acl' => { permissions_params: form.input_params["permissions"] } } end |
#validate ⇒ TrueClass, FalseClass
46 47 48 |
# File 'app/services/hyrax/action/create_valkyrie_work.rb', line 46 def validate form.validate(work_attributes) end |