Class: Unravel::Registry

Inherits:
Object
  • Object
show all
Defined in:
lib/unravel.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRegistry

Returns a new instance of Registry.



40
41
42
43
44
45
46
# File 'lib/unravel.rb', line 40

def initialize
  @fixes = {}
  @symptoms = {}
  @achievements = {}
  @contexts = {}
  @errors = {}
end

Instance Attribute Details

#achievementsObject (readonly)

Returns the value of attribute achievements.



38
39
40
# File 'lib/unravel.rb', line 38

def achievements
  @achievements
end

#contextsObject (readonly)

Returns the value of attribute contexts.



38
39
40
# File 'lib/unravel.rb', line 38

def contexts
  @contexts
end

#errorsObject (readonly)

Returns the value of attribute errors.



38
39
40
# File 'lib/unravel.rb', line 38

def errors
  @errors
end

#fixesObject (readonly)

Returns the value of attribute fixes.



38
39
40
# File 'lib/unravel.rb', line 38

def fixes
  @fixes
end

#symptomsObject (readonly)

Returns the value of attribute symptoms.



38
39
40
# File 'lib/unravel.rb', line 38

def symptoms
  @symptoms
end

Instance Method Details

#add_achievement(name, &block) ⇒ Object



71
72
73
# File 'lib/unravel.rb', line 71

def add_achievement(name, &block)
  @achievements[name] = block
end

#add_error_contexts(name, contexts) ⇒ Object



81
82
83
# File 'lib/unravel.rb', line 81

def add_error_contexts(name, contexts)
  @contexts[name] ||= contexts
end

#add_fix(name, block) ⇒ Object



58
59
60
61
# File 'lib/unravel.rb', line 58

def add_fix(name, block)
  fail HumanInterventionNeeded, "fix for root cause #{name} already exists" if @fixes.key?(name)
  @fixes[name] = block
end

#add_symptom(symptom, root_cause) ⇒ Object



67
68
69
# File 'lib/unravel.rb', line 67

def add_symptom(symptom, root_cause)
  @symptoms[symptom] = root_cause
end

#error_contexts_for_achievement(name) ⇒ Object



85
86
87
88
89
# File 'lib/unravel.rb', line 85

def error_contexts_for_achievement(name)
  @contexts[name].tap do |context|
    fail HumanInterventionNeeded, "No error handlers for achievement: #{name}" unless context
  end
end

#fixable_error(name) ⇒ Object



91
92
93
# File 'lib/unravel.rb', line 91

def fixable_error(name)
  @errors[name]
end

#get_achievement(name) ⇒ Object



75
76
77
78
79
# File 'lib/unravel.rb', line 75

def get_achievement(name)
  @achievements[name].tap do |achievement|
    fail HumanInterventionNeeded, "No such achievement: #{name.inspect}" unless achievement
  end
end

#get_fix_for(cause) ⇒ Object



52
53
54
55
56
# File 'lib/unravel.rb', line 52

def get_fix_for(cause)
  achievement_or_block = @fixes[cause]
  fail HumanInterventionNeeded, "No fix for: #{cause}" unless achievement_or_block
  achievement_or_block
end

#get_root_cause(symptom) ⇒ Object



63
64
65
# File 'lib/unravel.rb', line 63

def get_root_cause(symptom)
  @symptoms[symptom]
end

#has_fix_for?(cause) ⇒ Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/unravel.rb', line 48

def has_fix_for?(cause)
  @fixes.key?(cause)
end