Class: SmartPrompt::WorkerContext
- Inherits:
-
Object
- Object
- SmartPrompt::WorkerContext
show all
- Defined in:
- lib/smart_prompt/worker.rb
Instance Method Summary
collapse
Constructor Details
#initialize(conversation, params, engine, proc = nil) ⇒ WorkerContext
Returns a new instance of WorkerContext.
37
38
39
40
41
42
|
# File 'lib/smart_prompt/worker.rb', line 37
def initialize(conversation, params, engine, proc=nil)
@conversation = conversation
@params = params
@engine = engine
@proc = proc
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/smart_prompt/worker.rb', line 44
def method_missing(method, *args, &block)
if @conversation.respond_to?(method)
if method==:send_msg
if @proc==nil
@conversation.send_msg
else
@conversation.send_msg_by_stream(&@proc)
end
else
@conversation.send(method, *args, &block)
end
else
super
end
end
|
Instance Method Details
#call_worker(worker_name, params = {}) ⇒ Object
72
73
74
75
|
# File 'lib/smart_prompt/worker.rb', line 72
def call_worker(worker_name, params = {})
worker = Worker.new(worker_name, @engine)
worker.execute(params)
end
|
#call_worker_by_stream(worker_name, params = {}, proc) ⇒ Object
77
78
79
80
|
# File 'lib/smart_prompt/worker.rb', line 77
def call_worker_by_stream(worker_name, params = {}, proc)
worker = Worker.new(worker_name, @engine)
worker.execute_by_stream(params, proc)
end
|
#params ⇒ Object
64
65
66
|
# File 'lib/smart_prompt/worker.rb', line 64
def params
@params
end
|
#proc ⇒ Object
68
69
70
|
# File 'lib/smart_prompt/worker.rb', line 68
def proc
@proc
end
|
#respond_to_missing?(method, include_private = false) ⇒ Boolean
60
61
62
|
# File 'lib/smart_prompt/worker.rb', line 60
def respond_to_missing?(method, include_private = false)
@conversation.respond_to?(method) || super
end
|