Class: ServiceObjects::UpdateLegacyEmailTable

Inherits:
Base
  • Object
show all
Defined in:
lib/service_objects/update_legacy_email_table.rb

Constant Summary collapse

DB =
Sequel.connect(Settings.ws.db.to_hash)

Instance Attribute Summary

Attributes inherited from Base

#change

Instance Method Summary collapse

Methods inherited from Base

#call, ignore?, #initialize

Constructor Details

This class inherits a constructor from ServiceObjects::Base

Instance Method Details

#ignore?Boolean

Returns:

  • (Boolean)

18
19
20
# File 'lib/service_objects/update_legacy_email_table.rb', line 18

def ignore?
  !(change.affiliation_added? && !change.university_email_exists?)
end

#insert(email) ⇒ Object


5
6
7
# File 'lib/service_objects/update_legacy_email_table.rb', line 5

def insert(email)
  DB[:email].insert(idnumber: change.biola_id, email: email)
end

#insert_and_update(biola_id, old_email, new_email) ⇒ Object


9
10
11
12
13
14
15
16
# File 'lib/service_objects/update_legacy_email_table.rb', line 9

def insert_and_update(biola_id, old_email, new_email)
  DB[:email].where(idnumber: biola_id, email: old_email).update(primary: 0)
  if DB[:email].where(idnumber: biola_id, email: new_email).count > 0
    DB[:email].where(idnumber: biola_id, email: new_email).update(primary: 1, expiration_date: "0000-00-00 00:00:00")
  else
    DB[:email].insert(idnumber: biola_id, email: new_email)
  end
end