Class: SpreeCmCommissioner::UpdateGuestService
- Inherits:
-
Object
- Object
- SpreeCmCommissioner::UpdateGuestService
- Defined in:
- app/services/spree_cm_commissioner/update_guest_service.rb
Overview
Updates guest records with dynamic fields. Handles create/update/delete of dynamic fields with automatic cleanup of removed fields.
Instance Attribute Summary collapse
-
#guest ⇒ Object
readonly
Returns the value of attribute guest.
-
#guest_params ⇒ Object
readonly
Returns the value of attribute guest_params.
Instance Method Summary collapse
-
#call ⇒ Object
Updates guest within transaction: process dynamic fields → update attributes → move to next stage.
-
#initialize(guest, guest_params) ⇒ UpdateGuestService
constructor
A new instance of UpdateGuestService.
Constructor Details
#initialize(guest, guest_params) ⇒ UpdateGuestService
Returns a new instance of UpdateGuestService.
7 8 9 10 |
# File 'app/services/spree_cm_commissioner/update_guest_service.rb', line 7 def initialize(guest, guest_params) @guest = guest @guest_params = guest_params end |
Instance Attribute Details
#guest ⇒ Object (readonly)
Returns the value of attribute guest.
5 6 7 |
# File 'app/services/spree_cm_commissioner/update_guest_service.rb', line 5 def guest @guest end |
#guest_params ⇒ Object (readonly)
Returns the value of attribute guest_params.
5 6 7 |
# File 'app/services/spree_cm_commissioner/update_guest_service.rb', line 5 def guest_params @guest_params end |
Instance Method Details
#call ⇒ Object
Updates guest within transaction: process dynamic fields → update attributes → move to next stage
13 14 15 16 17 18 19 20 21 22 23 |
# File 'app/services/spree_cm_commissioner/update_guest_service.rb', line 13 def call ActiveRecord::Base.transaction do process_dynamic_fields(guest_params[:guest_dynamic_fields_attributes]) if guest_params[:guest_dynamic_fields_attributes] guest.assign_attributes(guest_params.except(:guest_dynamic_fields_attributes)) guest.save! guest.save_and_move_to_next_stage end guest end |