Class: Exemplar::Example

Inherits:
Object
  • Object
show all
Includes:
Loggable
Defined in:
lib/exemplar/example.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Loggable

#log, log=, log?

Constructor Details

#initialize(name, options, block) ⇒ Example

Returns a new instance of Example.



21
22
23
24
25
# File 'lib/exemplar/example.rb', line 21

def initialize(name, options, block)
  @name, @options, @block = name, options, block

  self.class.examples << self
end

Instance Attribute Details

#blockObject (readonly)

Returns the value of attribute block.



19
20
21
# File 'lib/exemplar/example.rb', line 19

def block
  @block
end

#nameObject (readonly)

Returns the value of attribute name.



19
20
21
# File 'lib/exemplar/example.rb', line 19

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



19
20
21
# File 'lib/exemplar/example.rb', line 19

def options
  @options
end

Class Method Details

.before(*before_methods) ⇒ Object



10
11
12
# File 'lib/exemplar/example.rb', line 10

def before(*before_methods)
  before_callbacks.push *before_methods
end

.before_callbacksObject



6
7
8
# File 'lib/exemplar/example.rb', line 6

def before_callbacks
  @before_callbacks ||= []
end

.examplesObject



14
15
16
# File 'lib/exemplar/example.rb', line 14

def examples
  @examples ||= []
end

Instance Method Details

#runObject



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/exemplar/example.rb', line 27

def run
  log "Running example #{name}..."

  block_return = run_before_callbacks && block.call(self)

  log "Done running example #{name}"

  block_return
rescue Exception => error
  rescue_error(error)
end