Class: Twilio::Rails::FindOrCreatePhoneCallerOperation
- Inherits:
-
ApplicationOperation
- Object
- ActiveOperation::Base
- ApplicationOperation
- Twilio::Rails::FindOrCreatePhoneCallerOperation
- Defined in:
- app/operations/twilio/rails/find_or_create_phone_caller_operation.rb
Overview
Finds and returns a Models::PhoneCaller by phone number, or creates a new one if it does not
exist. The operation will halt
if the phone number is not valid or blank.
Note: Operations should be called with call(params)
and not by calling new(params).execute
directly.
Instance Method Summary collapse
-
#execute ⇒ Twilio::Rails::Models::PhoneCaller
The found or newly created phone caller.
Instance Method Details
#execute ⇒ Twilio::Rails::Models::PhoneCaller
Returns The found or newly created phone caller.
13 14 15 16 17 18 19 20 |
# File 'app/operations/twilio/rails/find_or_create_phone_caller_operation.rb', line 13 def execute halt nil unless valid_phone_number phone_caller = ::Twilio::Rails.config.phone_caller_class.find_or_initialize_by(phone_number: valid_phone_number) phone_caller.save! if phone_caller.new_record? phone_caller end |