Class: CommandTower::Services::Me::UpdateName
- Inherits:
-
ApplicationService
- Object
- CommandTower::ServiceBase
- ApplicationService
- CommandTower::Services::Me::UpdateName
- Defined in:
- app/services/command_tower/services/me/update_name.rb
Constant Summary
Constants inherited from CommandTower::ServiceBase
CommandTower::ServiceBase::ON_ARGUMENT_VALIDATION
Instance Method Summary collapse
Methods inherited from ApplicationService
Methods included from Transactional
#fail_transaction!, #transaction
Methods inherited from CommandTower::ServiceBase
#command_tower_lifecycle, inherited, #internal_validate, #service_lifecycle_error_codes, #service_lifecycle_log_level, #validate!
Methods included from Logging::LifecycleDeclaration
Methods included from Execution::ContextAccess
#audit, #execution_context, #log_debug, #log_error, #log_info, #log_warn, #publish_event
Methods included from ArgumentValidation
Methods included from CommandTower::ServiceLogging
Instance Method Details
#call ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'app/services/command_tower/services/me/update_name.rb', line 11 def call normalized_first = first_name.to_s.strip normalized_last = last_name.to_s.strip first_changed = normalized_first != user.first_name.to_s last_changed = normalized_last != user.last_name.to_s unless first_changed || last_changed context.user = user return end application_error = nil ActiveRecord::Base.transaction do if first_changed application_error = mutate(first_name: normalized_first) raise ActiveRecord::Rollback if application_error end if last_changed application_error = mutate(last_name: normalized_last) raise ActiveRecord::Rollback if application_error end end if application_error context.fail!(application_error:) return end context.user = user.reload end |