Class: PUNK::CreateIdentitiesService

Inherits:
Service show all
Defined in:
lib/punk/services/create_identities.rb

Instance Attribute Summary

Attributes included from Validatable

#errors

Instance Method Summary collapse

Methods inherited from Service

#result, run

Methods included from Loggable

#exception, #logger, #profile_debug, #profile_info, #profile_trace

Methods inherited from Runnable

args, #method_missing, #respond_to_missing?

Methods included from Validatable

#default_validation_helpers_options, #get_column_value, #valid?, #validate, #validates_not_empty

Methods included from Plugins::Validation::InstanceMethods

#validates_email, #validates_event, #validates_phone, #validates_state, #validates_url

Methods inherited from Settings

#method_missing, #respond_to_missing?

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class PUNK::Runnable

Instance Method Details

#processObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/punk/services/create_identities.rb', line 5

def process
  User.each do |user|
    if user.email.present?
      Identity.find_or_create(claim: user.email) do |i|
        i.claim_type = :email
        i.user = user
      end
    end
    if user.phone.present?
      Identity.find_or_create(claim: user.phone) do |i|
        i.claim_type = :phone
        i.user = user
      end
    end
  rescue Sequel::ValidationFailed => e
    logger.warn e.message
  end
  nil
end