Class: Bianchi::USSD::Page
- Inherits:
-
Object
- Object
- Bianchi::USSD::Page
show all
- Includes:
- PageDelegators
- Defined in:
- lib/bianchi/ussd/page.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
#delegate_redirected_to, #delegate_render_and, #delegate_session, #handle_redirect_to_cases, #method_missing, #page_number, #to_menu_page, #to_next_or_previous_page
Constructor Details
#initialize(session) ⇒ Page
Returns a new instance of Page.
10
11
12
|
# File 'lib/bianchi/ussd/page.rb', line 10
def initialize(session)
@session = session
end
|
Instance Attribute Details
#session ⇒ Object
Returns the value of attribute session.
6
7
8
|
# File 'lib/bianchi/ussd/page.rb', line 6
def session
@session
end
|
Class Method Details
.call(session, action) ⇒ Object
14
15
16
17
18
19
20
21
|
# File 'lib/bianchi/ussd/page.rb', line 14
def self.call(session, action)
new(session).tap do |p|
p.ensure_methods_defined(%i[request response])
p.send(action)
rescue DispatchRenderException
p
end
end
|
Instance Method Details
#ensure_methods_defined(methods) ⇒ Object
54
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/bianchi/ussd/page.rb', line 54
def ensure_methods_defined(methods)
error_messages = methods.each_with_object([]) do |method, messages|
next if methods_defined? method
messages << "#{self.class.name} is supposed to have method #{method} defined"
end
return if error_messages.empty?
raise PageLoadError, error_messages.join(", ")
end
|
#load_page(page_number, menu_name) ⇒ Object
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/bianchi/ussd/page.rb', line 38
def load_page(page_number, )
constant_name = "USSD::#{.camelize}Menu::#{page_number}"
page = constant_name.safe_constantize
unless page
raise PageLoadError, <<~MSG
\n
#{constant_name} is supposed to be defined to process #{} menu #{page_number}.
generate menu page with `bianchi g menu #{} page #{page_number[4..]}`
MSG
end
session. = Menu.new()
page.new(session).send(:request)
end
|
#methods_defined?(method) ⇒ Boolean
66
67
68
|
# File 'lib/bianchi/ussd/page.rb', line 66
def methods_defined?(method)
respond_to? method
end
|
#render(body, options = {}) ⇒ Object
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/bianchi/ussd/page.rb', line 23
def render(body, options = {})
raise ArgumentError, "render body expected to be a string" unless body.is_a? String
session.tap do |s|
s.prompt_data = s.params.merge(
{ activity_state: options[:state], body: body }
)
s.page_number = self.class.name.split("::").last
s.store.track_session
end
raise DispatchRenderException
end
|