Class: Contr::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/contr/base.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(instance_config = {}) ⇒ Base

Returns a new instance of Base.



48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/contr/base.rb', line 48

def initialize(instance_config = {})
  @config = merge_configs(instance_config)

  init_logger!
  init_sampler!
  init_main_pool!
  init_rules_pool!

  aggregate_guarantees!
  aggregate_expectations!

  freeze
end

Class Attribute Details

.configObject (readonly)

Returns the value of attribute config.



6
7
8
# File 'lib/contr/base.rb', line 6

def config
  @config
end

.expectationsObject (readonly)

Returns the value of attribute expectations.



6
7
8
# File 'lib/contr/base.rb', line 6

def expectations
  @expectations
end

.guaranteesObject (readonly)

Returns the value of attribute guarantees.



6
7
8
# File 'lib/contr/base.rb', line 6

def guarantees
  @guarantees
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



46
47
48
# File 'lib/contr/base.rb', line 46

def config
  @config
end

#expectationsObject (readonly)

Returns the value of attribute expectations.



46
47
48
# File 'lib/contr/base.rb', line 46

def expectations
  @expectations
end

#guaranteesObject (readonly)

Returns the value of attribute guarantees.



46
47
48
# File 'lib/contr/base.rb', line 46

def guarantees
  @guarantees
end

#loggerObject (readonly)

Returns the value of attribute logger.



46
47
48
# File 'lib/contr/base.rb', line 46

def logger
  @logger
end

#main_poolObject (readonly)

Returns the value of attribute main_pool.



46
47
48
# File 'lib/contr/base.rb', line 46

def main_pool
  @main_pool
end

#rules_poolObject (readonly)

Returns the value of attribute rules_pool.



46
47
48
# File 'lib/contr/base.rb', line 46

def rules_pool
  @rules_pool
end

#samplerObject (readonly)

Returns the value of attribute sampler.



46
47
48
# File 'lib/contr/base.rb', line 46

def sampler
  @sampler
end

Class Method Details

.async(async) ⇒ Object



8
9
10
# File 'lib/contr/base.rb', line 8

def async(async)
  set_config(:async, async)
end

.expect(name, &block) ⇒ Object



24
25
26
# File 'lib/contr/base.rb', line 24

def expect(name, &block)
  add_expectation(name, block)
end

.guarantee(name, &block) ⇒ Object



20
21
22
# File 'lib/contr/base.rb', line 20

def guarantee(name, &block)
  add_guarantee(name, block)
end

.logger(logger) ⇒ Object



12
13
14
# File 'lib/contr/base.rb', line 12

def logger(logger)
  set_config(:logger, logger)
end

.sampler(sampler) ⇒ Object



16
17
18
# File 'lib/contr/base.rb', line 16

def sampler(sampler)
  set_config(:sampler, sampler)
end

Instance Method Details

#check(*args) ⇒ Object



62
63
64
65
66
# File 'lib/contr/base.rb', line 62

def check(*args)
  result = yield
  Matcher::Sync.new(self, args, result).match
  result
end

#check_async(*args) ⇒ Object



68
69
70
71
72
# File 'lib/contr/base.rb', line 68

def check_async(*args)
  result = yield
  Matcher::Async.new(self, args, result).match
  result
end

#nameObject



74
75
76
# File 'lib/contr/base.rb', line 74

def name
  self.class.name
end