Sha256: 13960a9132c1636f5a93ab17dad849be677a489b898392c8803253e07a6dcd7a

Contents?: true

Size: 1.53 KB

Versions: 16

Compression:

Stored size: 1.53 KB

Contents

module Eco
  module API
    module UseCases
      class DefaultCases
        class ChangeEMailCase < BaseCase

          def process
            @cases.define("change-email", type: :sync) do |entries, people, session|
              remove = session.job_group("main").new("remove account", type: :update, sets: :account)
              change = session.job_group("main").new("change email", type: :update, sets: :core)
              add_account = session.job_group("post").new("add account", type: :update, sets: :account)

              entries.each.with_index do |entry, i|
                person = people.find(entry)

                if !person
                  session.logger.error("Entry(#{i}) - this person does not exist: #{entry.to_s(:identify)}")
                else
                  unless entry.email.downcase == person.email
                    account = person.account
                    person.account = nil
                    remove.add(person)

                    new_email = entry.email
                    change.add(person) do |person|
                      person.sync
                      person.email = new_email
                      person
                    end

                    add_account.add(person) do |person|
                      person.sync
                      person.account = account
                      person
                    end
                  end

                end
              end
            end
          end

        end
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
eco-helpers-0.6.17 lib/eco/api/usecases/default_cases/change_email_case.rb
eco-helpers-0.6.16 lib/eco/api/usecases/default_cases/change_email_case.rb
eco-helpers-0.6.15 lib/eco/api/usecases/default_cases/change_email_case.rb
eco-helpers-0.6.13 lib/eco/api/usecases/default_cases/change_email_case.rb
eco-helpers-0.6.12 lib/eco/api/usecases/default_cases/change_email_case.rb
eco-helpers-0.6.11 lib/eco/api/usecases/default_cases/change_email_case.rb
eco-helpers-0.6.9 lib/eco/api/usecases/default_cases/change_email_case.rb
eco-helpers-0.6.8 lib/eco/api/usecases/default_cases/change_email_case.rb
eco-helpers-0.6.7 lib/eco/api/usecases/default_cases/change_email_case.rb
eco-helpers-0.6.6 lib/eco/api/usecases/default_cases/change_email_case.rb
eco-helpers-0.6.5 lib/eco/api/usecases/default_cases/change_email_case.rb
eco-helpers-0.6.4 lib/eco/api/usecases/default_cases/change_email_case.rb
eco-helpers-0.6.3 lib/eco/api/usecases/default_cases/change_email_case.rb
eco-helpers-0.6.2 lib/eco/api/usecases/default_cases/change_email_case.rb
eco-helpers-0.6.1 lib/eco/api/usecases/default_cases/change_email_case.rb
eco-helpers-0.6.0 lib/eco/api/usecases/default_cases/change_email_case.rb