Class: Brute::Eval::World

Inherits:
Object
  • Object
show all
Defined in:
lib/brute/eval/world.rb

Overview

The world a case wakes up in.

This one keeps nothing: what was said is handed straight to the turn, and the tools answer from the case's stubs. It is what a plain agent needs, and it is the contract a deployment's own world implements -- a world is anything that answers:

#prepare(case)      lay the world out for this case, and answer what
                  the turn should be started with (nil when the
                  world delivered what was said some other way, an
                  inbox on disk say)
#stub(agent, stubs) install the case's canned tool results
#published          whatever the turn sent outward, for the record

Subclass to give a case somewhere to wake up:

class Room < Brute::Eval::World
def prepare(kase)
  super.tap { |input| inbox.append(kase.said) if input.nil? }
end
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeWorld

Returns a new instance of World.



32
33
34
# File 'lib/brute/eval/world.rb', line 32

def initialize
  @published = []
end

Instance Attribute Details

#publishedObject (readonly)

Returns the value of attribute published.



30
31
32
# File 'lib/brute/eval/world.rb', line 30

def published
  @published
end

Instance Method Details

#prepare(kase) ⇒ Object



36
37
38
39
# File 'lib/brute/eval/world.rb', line 36

def prepare(kase)
  @published.clear
  kase.said
end

#stub(agent, stubs) ⇒ Object

:before_tool is handed a mutable call env, and a :result set on it is answered without the tool ever running -- so a stub replaces the web, the calendar or the shell without the agent being built differently. A stub that answers to #call is handed the arguments.



45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/brute/eval/world.rb', line 45

def stub(agent, stubs)
  agent.on(:before_tool) do |_env, call|
    canned = stubs[call[:name]]

    unless canned.nil?
      if canned.respond_to?(:call)
        call[:result] = canned.call(call[:arguments])
      else
        call[:result] = canned
      end
    end
  end
end