Class: SmartPrompt::WorkerContext

Inherits:
Object
  • Object
show all
Defined in:
lib/smart_prompt/worker.rb

Instance Method Summary collapse

Constructor Details

#initialize(conversation, params, engine) ⇒ WorkerContext

Returns a new instance of WorkerContext.



31
32
33
34
35
# File 'lib/smart_prompt/worker.rb', line 31

def initialize(conversation, params, engine)
  @conversation = conversation
  @params = params
  @engine = engine
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/smart_prompt/worker.rb', line 37

def method_missing(method, *args, &block)
  if @conversation.respond_to?(method)
    @conversation.send(method, *args, &block)
  else
    super
  end
end

Instance Method Details

#call_worker(worker_name, params = {}) ⇒ Object



53
54
55
56
# File 'lib/smart_prompt/worker.rb', line 53

def call_worker(worker_name, params = {})
  worker = Worker.new(worker_name, @engine)
  worker.execute(params)
end

#paramsObject



49
50
51
# File 'lib/smart_prompt/worker.rb', line 49

def params
  @params
end

#respond_to_missing?(method, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/smart_prompt/worker.rb', line 45

def respond_to_missing?(method, include_private = false)
  @conversation.respond_to?(method) || super
end