Last active
August 29, 2015 14:04
-
-
Save olvap/90c8f9bec16bc1f726ca to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def verify_phone_pin_and_delete_in_call_records(phone_verification_input) | |
| verified = false | |
| if self.phone_number.nil? && self.is_suspicious && verify_proposed_phone_pin(phone_verification_input) | |
| verified = true | |
| TwilioCall.find_by_user_id(self.id).try(:destroy) | |
| elsif self.proposed_phone_number && verify_proposed_phone_pin(phone_verification_input) | |
| verified = true | |
| TwilioCall.find_by_user_id(self.id).try(:destroy) | |
| elsif !self.proposed_phone_number && verify_phone_pin(phone_verification_input) | |
| verified = true | |
| TwilioCall.find_by_user_id(self.id).try(:destroy) | |
| end | |
| return verified | |
| end | |
| def requires_phone_verification? | |
| if !self.phone_verified_at || self.proposed_phone_number | |
| requires_phone_verification = true | |
| else | |
| requires_phone_verification = false | |
| end | |
| return requires_phone_verification | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| has_many :twilio_calls | |
| def verify_phone_pin_and_delete_in_call_records(phone_verification_input) | |
| twilio_calls.destroy if should_destroy? | |
| end | |
| # you don`t need to set a variable to true is the stament is true. | |
| # if should_destroy? is true, the first part returns an object, and if its false, returns nil. | |
| # hen you call verify_phone_pin_and_delete_in_call_records(phone_verification_input) | |
| # is going to return object or nil | |
| def should_destroy? | |
| (phone_number && is_suspicious && verify_proposed_phone_pin(phone_verification_input)) || | |
| (proposed_phone_number && verify_proposed_phone_pin(phone_verification_input)) || | |
| (!proposed_phone_number && verify_phone_pin(phone_verification_input)) | |
| end | |
| def requires_phone_verification? | |
| !phone_verified_at || proposed_phone_number | |
| end | |
| # The last thing you sent in a method is the response of it. | |
| # son you could move the if stament to its own method. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment