~singpolyma/sgx-jmp

ref: 045da39f25b74034e7bba44cb5f1db48a935ba84 sgx-jmp/lib/legacy_customer.rb -rw-r--r-- 960 bytes
045da39fStephen Paul Weber Hotfix: arguments in wrong order 1 year, 3 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# frozen_string_literal: true

require "value_semantics/monkey_patched"
require_relative "proxied_jid"

class LegacyCustomer
	attr_reader :jid, :tel

	def initialize(jid, tel)
		@jid = jid
		@tel = tel
	end

	def customer_id
		nil
	end

	def info
		EMPromise.resolve(nil).then do
			Info.new(jid: jid, tel: tel)
		end
	end

	def admin_info
		EMPromise.all([
			info,
			api
		]).then do |info, api|
			AdminInfo.new(info: info, api: api)
		end
	end

	def api
		API.for(self)
	end

	class Info
		value_semantics do
			jid ProxiedJID, coerce: ProxiedJID.method(:new)
			tel String
		end

		def fields
			[
				{ var: "JID", value: jid.unproxied.to_s },
				{ var: "Phone Number", value: tel }
			]
		end
	end

	class AdminInfo
		value_semantics do
			info Info
			api API
		end

		def fields
			info.fields + [
				{ var: "Account Status", value: "Legacy" },
				{ var: "Cheo JID", value: info.jid.to_s },
				{ var: "API", value: api.to_s }
			]
		end
	end
end