Class: Rdbc::Contract

Inherits:
Object
  • Object
show all
Extended by:
Translating
Includes:
Translating
Defined in:
lib/rdbc/contract.rb

Defined Under Namespace

Classes: AssertionFailed

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Translating

method_post, method_pre, method_with_prefix, operator

Class Method Details

.invariant(&block) ⇒ Object



14
15
16
# File 'lib/rdbc/contract.rb', line 14

def invariant(&block)
  define_method(:invariant, &block)
end

.post(method, &block) ⇒ Object



10
11
12
# File 'lib/rdbc/contract.rb', line 10

def post(method, &block)
  define_method(method_post(method), &block)
end

.pre(method, &block) ⇒ Object



6
7
8
# File 'lib/rdbc/contract.rb', line 6

def pre(method, &block)
  define_method(method_pre(method), &block)
end

Instance Method Details

#assert(condition) ⇒ Object

Raises:



24
25
26
# File 'lib/rdbc/contract.rb', line 24

def assert(condition)
  raise AssertionFailed unless condition
end

#send_invariant(object) ⇒ Object



35
36
37
38
39
# File 'lib/rdbc/contract.rb', line 35

def send_invariant(object)
  if respond_to?(:invariant)
    invariant(object)
  end
end

#send_method_post(method, object_pre, object, exception, result, *args) ⇒ Object



41
42
43
44
45
46
# File 'lib/rdbc/contract.rb', line 41

def send_method_post(method, object_pre, object, exception, result, *args)
  method_post = method_post(method)
  if respond_to?(method_post)
    send(method_post, object_pre, object, exception, result, *args)
  end
end

#send_method_pre(method, object, *args) ⇒ Object



28
29
30
31
32
33
# File 'lib/rdbc/contract.rb', line 28

def send_method_pre(method, object, *args)
  method_pre = method_pre(method)
  if respond_to?(method_pre)
    send(method_pre, object, *args)
  end
end