Class: Riot::RunnableBlock

Inherits:
Object show all
Defined in:
lib/riot/runnable.rb

Overview

A runnable block is pretty much an anonymous block decorator. It’s goal is to accept a block, a description for what the block is intended to be for, and provide a run method expects a Situation instance. Any time a Situation is provided to run, a RunnableBlock promises to evaluate itself against the situation in some way.

Intent is to sub-class RunnableBlock with specific mechanisms for contorting the Situation.

Direct Known Subclasses

Assertion, Helper, Setup

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(description, &definition) ⇒ RunnableBlock

Creates a new RunnableBlock.

Parameters:

  • description (String)

    a description of what this block is for

  • &definition (lambda)

    the block to decorate



18
19
20
# File 'lib/riot/runnable.rb', line 18

def initialize(description, &definition)
  @description, @definition = description, definition || proc { false }
end

Instance Attribute Details

#definitionObject (readonly)

The decorated block.



12
13
14
# File 'lib/riot/runnable.rb', line 12

def definition
  @definition
end

Instance Method Details

#run(situation) ⇒ Array<Symbol[, String]>

Given a Situation, eval the provided block against it and then return a status tuple.

Parameters:

Returns:

  • (Array<Symbol[, String]>)

    array containing at least an evaluation state



26
27
28
# File 'lib/riot/runnable.rb', line 26

def run(situation)
  raise "Define your own run"
end

#to_sString

String representation of this block, which is basically the description.

Returns:

  • (String)


33
# File 'lib/riot/runnable.rb', line 33

def to_s; @description; end