Module: Hospital

Defined in:
lib/railtie.rb,
lib/hospital.rb,
lib/hospital/checkup.rb,
lib/hospital/version.rb,
lib/hospital/checkup_group.rb,
lib/hospital/formatter/pre.rb,
lib/hospital/formatter/base.rb,
lib/hospital/formatter/shell.rb

Defined Under Namespace

Modules: Formatter Classes: Checkup, CheckupGroup, Diagnosis, Error, Railtie, Runner

Constant Summary collapse

VERSION =
"0.7.4"
@@groups =
[]

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.do_checkup(klass, verbose: false, ignore_condition: false) ⇒ Object

used to call the checkup for a specific class directly (in specs)



27
28
29
30
31
# File 'lib/hospital.rb', line 27

def do_checkup(klass, verbose: false, ignore_condition: false)
  @@groups.map(&:all_checkups).flatten.select{|cu| cu.klass == klass }.map do |cu|
    cu.check verbose: verbose, ignore_condition: ignore_condition
  end
end

.find_or_create_checkup_group(name) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/hospital.rb', line 33

def find_or_create_checkup_group name
  unless checkup_group = @@groups.detect{|g| g.name == name }
    checkup_group = CheckupGroup.new name
    @@groups << checkup_group
  end
  checkup_group
end

.groupsObject



41
42
43
# File 'lib/hospital.rb', line 41

def groups
  @@groups
end

.included(klass) ⇒ Object

Raises:



22
23
24
# File 'lib/hospital.rb', line 22

def included(klass)
  raise Hospital::Error.new("Cannot include Hospital, please extend instead.")
end

Instance Method Details

#checkup(if: -> { true }, group: :general, title: nil, precondition: false, &code) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/hospital.rb', line 46

def checkup if: -> { true }, group: :general, title: nil, precondition: false, &code
  checkup_group = Hospital.find_or_create_checkup_group group
  checkup = Checkup.new(
    self,
    code,
    title:        title,
    condition:    binding.local_variable_get('if'),
    precondition: precondition
  )

  # p "adding #{checkup.inspect} to #{group_name}"
  checkup_group.add_checkup checkup
end