Class: Checkers::Check

Inherits:
Object
  • Object
show all
Includes:
Checks, Sugar
Defined in:
lib/checkers.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Checks

#==, #empty, #includes, #matches, #raises

Methods included from Sugar

#are, #is, #not

Constructor Details

#initialize(subject, caller, run = Checkers.run) ⇒ Check



41
42
43
44
45
46
47
# File 'lib/checkers.rb', line 41

def initialize(subject, caller, run = Checkers.run)
  @subject = subject
  @caller = caller
  @message = ''
  @inverted = false
  @run = run
end

Instance Attribute Details

#callerObject (readonly)

Returns the value of attribute caller.



39
40
41
# File 'lib/checkers.rb', line 39

def caller
  @caller
end

#invertedObject (readonly)

Returns the value of attribute inverted.



39
40
41
# File 'lib/checkers.rb', line 39

def inverted
  @inverted
end

#messageObject

Returns the value of attribute message.



39
40
41
# File 'lib/checkers.rb', line 39

def message
  @message
end

#runObject (readonly)

Returns the value of attribute run.



39
40
41
# File 'lib/checkers.rb', line 39

def run
  @run
end

#subjectObject (readonly)

Returns the value of attribute subject.



39
40
41
# File 'lib/checkers.rb', line 39

def subject
  @subject
end

Instance Method Details

#check(condition, msg = 'Check failed.') ⇒ Object



49
50
51
52
53
# File 'lib/checkers.rb', line 49

def check(condition, msg = 'Check failed.')
  self.message = msg
  condition = !condition if inverted
  condition ? run.pass(self) : run.fail(self)
end