~singpolyma/sgx-jmp

ref: c7c48663714307e3598dc14848e539fb8672b0b7 sgx-jmp/lib/legacy_customer.rb -rw-r--r-- 834 bytes
c7c48663Christopher Vollick Customer Info Forms and More Info 4 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
# 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(tel: tel)
		end
	end

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

	def api
		API.for(self)
	end

	class Info
		value_semantics do
			tel String
		end

		def form
			FormTemplate.render("legacy_customer_info", info: self)
		end
	end

	class AdminInfo
		value_semantics do
			info Info
			jid ProxiedJID, coerce: ProxiedJID.method(:new)
			api API
		end

		def form
			FormTemplate.render("legacy_customer_admin_info", admin_info: self)
		end
	end
end