Class: Browserctl::WorkflowContext
- Inherits:
-
Object
- Object
- Browserctl::WorkflowContext
show all
- Defined in:
- lib/browserctl/workflow.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of WorkflowContext.
17
18
19
20
|
# File 'lib/browserctl/workflow.rb', line 17
def initialize(params, client)
@params = params
@client = client
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
36
37
38
39
40
|
# File 'lib/browserctl/workflow.rb', line 36
def method_missing(name, *args)
return @params[name] if @params.key?(name)
super
end
|
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
15
16
17
|
# File 'lib/browserctl/workflow.rb', line 15
def client
@client
end
|
Instance Method Details
#ask(prompt) ⇒ Object
94
95
96
97
|
# File 'lib/browserctl/workflow.rb', line 94
def ask(prompt)
$stderr.print("[browserctl] #{prompt} ")
$stdin.gets.chomp
end
|
#assert(condition, msg = "assertion failed") ⇒ Object
105
106
107
|
# File 'lib/browserctl/workflow.rb', line 105
def assert(condition, msg = "assertion failed")
raise WorkflowError, msg unless condition
end
|
#close_page(page_name) ⇒ Object
57
58
59
60
61
62
|
# File 'lib/browserctl/workflow.rb', line 57
def close_page(page_name)
res = @client.page_close(page_name.to_s)
raise WorkflowError, res[:error] if res[:error]
res
end
|
#fetch(key) ⇒ Object
29
30
31
32
33
34
|
# File 'lib/browserctl/workflow.rb', line 29
def fetch(key)
res = @client.fetch(key.to_s)
raise WorkflowError, res[:error] if res[:error]
res[:value]
end
|
#invoke(workflow_name, **override_params) ⇒ Object
99
100
101
102
103
|
# File 'lib/browserctl/workflow.rb', line 99
def invoke(workflow_name, **override_params)
name = workflow_name.to_s
guard_circular!(name)
track_invoke(name) { run_nested(workflow_name, **override_params) }
end
|
#list_sessions ⇒ Object
90
91
92
|
# File 'lib/browserctl/workflow.rb', line 90
def list_sessions
@client.session_list[:sessions]
end
|
#load_session(session_name, fallback: nil) ⇒ Object
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
# File 'lib/browserctl/workflow.rb', line 71
def load_session(session_name, fallback: nil)
res = @client.session_load(session_name)
return res unless res[:error]
raise WorkflowError, res[:error] unless fallback
invoke(fallback.to_s)
res2 = @client.session_load(session_name)
if res2[:error]
msg = "session '#{session_name}' still unavailable after running fallback '#{fallback}'"
unless Session.exist?(session_name)
msg += "\n Hint: '#{fallback}' did not call save_session(\"#{session_name}\") — add it as the last step."
end
raise WorkflowError, msg
end
res2
end
|
#open_page(page_name, url: nil) ⇒ Object
50
51
52
53
54
55
|
# File 'lib/browserctl/workflow.rb', line 50
def open_page(page_name, url: nil)
res = @client.page_open(page_name.to_s, url: url)
raise WorkflowError, res[:error] if res[:error]
res
end
|
#page(name) ⇒ Object
46
47
48
|
# File 'lib/browserctl/workflow.rb', line 46
def page(name)
PageProxy.new(name.to_s, @client)
end
|
#respond_to_missing?(name, include_private = false) ⇒ Boolean
42
43
44
|
# File 'lib/browserctl/workflow.rb', line 42
def respond_to_missing?(name, include_private = false)
@params.key?(name) || super
end
|
#save_session(session_name, encrypt: false) ⇒ Object
64
65
66
67
68
69
|
# File 'lib/browserctl/workflow.rb', line 64
def save_session(session_name, encrypt: false)
res = @client.session_save(session_name, encrypt: encrypt)
raise WorkflowError, res[:error] if res[:error]
res
end
|
#store(key, value) ⇒ Object
22
23
24
25
26
27
|
# File 'lib/browserctl/workflow.rb', line 22
def store(key, value)
res = @client.store(key.to_s, value)
raise WorkflowError, res[:error] if res[:error]
value
end
|