Class: Doctrine::Definition

Inherits:
Object
  • Object
show all
Includes:
Is::Stateful
Defined in:
lib/doctrine/definition.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.subject(value = value_omitted = true, &block) ⇒ Object


10
11
12
13
14
15
16
17
18
# File 'lib/doctrine/definition.rb', line 10

def subject(value = value_omitted = true, &block)
  if block
    @subject = block
    @subject_type = :block
  elsif !value_omitted
    @subject = value
    @subject_type = :value
  end
end

.tenet(description, &block) ⇒ Object


20
21
22
# File 'lib/doctrine/definition.rb', line 20

def tenet(description, &block)
  tenets << Tenet.new(description: description, &block)
end

Instance Method Details

#assertObject

public

42
43
44
45
46
47
48
49
50
51
52
# File 'lib/doctrine/definition.rb', line 42

def assert
  subject, subject_type = find_subject_and_subject_type

  if subject_type
    unless yield(resolve(subject, subject_type))
      raise AssertionFailed
    end
  else
    raise UndefinedSubject
  end
end

#captureObject

public

56
57
58
59
60
61
# File 'lib/doctrine/definition.rb', line 56

def capture
  yield
rescue => error
  @subject_type = :error
  @subject = error
end

#subject(value = value_omitted = true, &block) ⇒ Object

public

30
31
32
33
34
35
36
37
38
# File 'lib/doctrine/definition.rb', line 30

def subject(value = value_omitted = true, &block)
  if block
    @subject = block
    @subject_type = :block
  elsif !value_omitted
    @subject = value
    @subject_type = :value
  end
end