Class: AE::Check::Proc

Inherits:
Object show all
Defined in:
lib/ae/check.rb

Overview

The Check::Proc class encapsulates a labeled procedure for making assertions using the `ok`/`no` methods.

Instance Method Summary collapse

Constructor Details

#initialize(options = {}, &check) ⇒ Proc

Setup new check procedure.


14
15
16
17
18
# File 'lib/ae/check.rb', line 14

def initialize(options={}, &check)
  @name    = options[:name]
  @message = options[:message] || @name
  @check   = check
end

Instance Method Details

#call(*args) ⇒ Object

Call check procedure.


34
35
36
# File 'lib/ae/check.rb', line 34

def call(*args)
  @check.call(*args)
end

#message(&block) ⇒ Object


21
22
23
24
25
26
# File 'lib/ae/check.rb', line 21

def message(&block)
  if block
    @message = message
  end
  @message
end

#message=(msg) ⇒ Object


29
30
31
# File 'lib/ae/check.rb', line 29

def message=(msg)
  @message = msg
end

#no!(*args) ⇒ Object


57
58
59
# File 'lib/ae/check.rb', line 57

def no!(*args)
  refute(call(*args), to_s(*args))
end

#ok!(*args) ⇒ Object


52
53
54
# File 'lib/ae/check.rb', line 52

def ok!(*args)
  assert(call(*args), to_s(*args))
end

#to_s(*args) ⇒ Object


39
40
41
42
43
44
45
46
47
48
49
# File 'lib/ae/check.rb', line 39

def to_s(*args)
  case @message
  when nil
    @name.to_s
  when ::Proc
    @message.call(*args)
  else
    # TODO: count %\S and apply `% args.map{|a|a.inspect}[0,count]`
    @message.to_s
  end
end