Class: Rocksteady::Scenario

Inherits:
Object
  • Object
show all
Defined in:
lib/rocksteady/scenario.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(corpus, title, &operation) ⇒ Scenario

Returns a new instance of Scenario.



6
7
8
9
10
# File 'lib/rocksteady/scenario.rb', line 6

def initialize(corpus, title, &operation)
  @corpus = corpus
  @title = title
  @operation = operation
end

Instance Attribute Details

#corpusObject (readonly)

Returns the value of attribute corpus.



5
6
7
# File 'lib/rocksteady/scenario.rb', line 5

def corpus
  @corpus
end

#operationObject (readonly)

Returns the value of attribute operation.



5
6
7
# File 'lib/rocksteady/scenario.rb', line 5

def operation
  @operation
end

#titleObject (readonly)

Returns the value of attribute title.



5
6
7
# File 'lib/rocksteady/scenario.rb', line 5

def title
  @title
end

Instance Method Details

#nameObject



16
17
18
# File 'lib/rocksteady/scenario.rb', line 16

def name
  @name ||= title.gsub(/[^[:alnum:]]+/, '_').downcase
end

#resultObject Also known as: run!



20
21
22
23
24
25
26
# File 'lib/rocksteady/scenario.rb', line 20

def result
  @result ||= begin
    operation.call
  rescue Exception => e
    e
  end
end

#schedule!Object



12
13
14
# File 'lib/rocksteady/scenario.rb', line 12

def schedule!
  corpus.schedule << self
end