Class: Wf::CaseCommand::CreateEntry
- Inherits:
-
Object
- Object
- Wf::CaseCommand::CreateEntry
- Includes:
- SimpleCommand
- Defined in:
- app/models/wf/case_command/create_entry.rb
Instance Attribute Summary collapse
-
#form ⇒ Object
readonly
Returns the value of attribute form.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
-
#workitem ⇒ Object
readonly
Returns the value of attribute workitem.
Instance Method Summary collapse
- #call ⇒ Object
- #create_entry ⇒ Object
-
#initialize(form, workitem, user, params) ⇒ CreateEntry
constructor
A new instance of CreateEntry.
Constructor Details
#initialize(form, workitem, user, params) ⇒ CreateEntry
Returns a new instance of CreateEntry.
7 8 9 10 11 12 |
# File 'app/models/wf/case_command/create_entry.rb', line 7 def initialize(form, workitem, user, params) @form = form @workitem = workitem @params = params @user = user end |
Instance Attribute Details
#form ⇒ Object (readonly)
Returns the value of attribute form.
6 7 8 |
# File 'app/models/wf/case_command/create_entry.rb', line 6 def form @form end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
6 7 8 |
# File 'app/models/wf/case_command/create_entry.rb', line 6 def params @params end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
6 7 8 |
# File 'app/models/wf/case_command/create_entry.rb', line 6 def user @user end |
#workitem ⇒ Object (readonly)
Returns the value of attribute workitem.
6 7 8 |
# File 'app/models/wf/case_command/create_entry.rb', line 6 def workitem @workitem end |
Instance Method Details
#call ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'app/models/wf/case_command/create_entry.rb', line 14 def call create_entry rescue StandardError binding.pry puts $ERROR_INFO # TODO: more detail errors.add(:base, :failure) end |
#create_entry ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'app/models/wf/case_command/create_entry.rb', line 23 def create_entry Wf::ApplicationRecord.transaction do entry = form.entries.find_or_create_by!(user: user, workitem: workitem) params.each do |field_id, field_value| if field = entry.field_values.where(form: form, field_id: field_id).first field.update!(value: field_value) else entry.field_values.create!(form: form, field_id: field_id, value: field_value) end end entry.update_payload! entry end end |