Class: Lusnoc::Guard

Inherits:
Object
  • Object
show all
Includes:
Helper
Defined in:
lib/lusnoc/guard.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helper

#build_url, #logger

Constructor Details

#initialize(base_url) {|_self| ... } ⇒ Guard

Returns a new instance of Guard.

Yields:

  • (_self)

Yield Parameters:

  • _self (Lusnoc::Guard)

    the object that the method was called on



11
12
13
14
15
# File 'lib/lusnoc/guard.rb', line 11

def initialize(base_url)
  @base_url = base_url
  @callbacks = {}
  yield(self) if block_given?
end

Instance Attribute Details

#callbacksObject (readonly)

Returns the value of attribute callbacks.



9
10
11
# File 'lib/lusnoc/guard.rb', line 9

def callbacks
  @callbacks
end

Instance Method Details

#condition(&block) ⇒ Object



17
18
19
20
# File 'lib/lusnoc/guard.rb', line 17

def condition(&block)
  @callbacks[:condition] = block
  self
end

#runObject



27
28
29
30
31
32
# File 'lib/lusnoc/guard.rb', line 27

def run
  th = start_thread
  yield
ensure
  th.kill rescue nil
end

#then(&block) ⇒ Object



22
23
24
25
# File 'lib/lusnoc/guard.rb', line 22

def then(&block)
  @callbacks[:then] = block
  self
end