propershark / shark

An event publisher for realtime transit information.
3 stars 0 forks source link

Create a REPL for testing #28

Closed faultyserver closed 8 years ago

faultyserver commented 8 years ago

There should be a system that allows developers to run an instance of Shark that exposes a REPL, allowing them to interact with and inspect Events as the pass through the system. Ideally, the REPL could be inserted anywhere above Agency in the Middleware stack, but will default to the end of the stack.

Running the REPL should be simple, something akin to

ruby shark.rb --repl [--insert-after <MiddlewareClassName>]

An example of a session with the REPL:

$ ruby shark.rb --repl
>> last_event
<Event:0x... @topic="vehicles.4004">
>> event = last_event(topic: "routes.1B")
<Event0x... @topic="routes.1B">
>> event.type
:update
>> event.originator
<Shark::Route:0x... @identifier="routes.1B">
>> exit
$

Essentially, the REPL should be an instance of IRB (or rather, Ripl) with a few helpers defined to make interacting with events simpler.

faultyserver commented 8 years ago

FWIW, this is done. The REPL is automatically started when Shark is run in the test environment.

Example:

$ bin/shark -c config/citybus.rb -e test
| Loading configuration
| Loading agency
| Preparing environment
| Ready
>> fetch 'vehicles.4008'
=> #<Shark::Vehicle:0x007ffed30aaaa8 @associated_objects={}, @name="4008", @latitude=40.4191925, @longitude=-86.894239666667, @route="routes.1B", @last_station="stations.BUS215">
>> 

With that, I'm going to close this issue. It doesn't mean that the REPL is finished, just that there is a working REPL with helpers.