Class: Unravel::Registry
- Inherits:
-
Object
- Object
- Unravel::Registry
- Defined in:
- lib/unravel.rb
Instance Attribute Summary collapse
-
#achievements ⇒ Object
readonly
Returns the value of attribute achievements.
-
#contexts ⇒ Object
readonly
Returns the value of attribute contexts.
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#fixes ⇒ Object
readonly
Returns the value of attribute fixes.
-
#symptoms ⇒ Object
readonly
Returns the value of attribute symptoms.
Instance Method Summary collapse
- #add_achievement(name, &block) ⇒ Object
- #add_error_contexts(name, contexts) ⇒ Object
- #add_fix(name, block) ⇒ Object
- #add_symptom(symptom, root_cause) ⇒ Object
- #error_contexts_for_achievement(name) ⇒ Object
- #fixable_error(name) ⇒ Object
- #get_achievement(name) ⇒ Object
- #get_fix(name) ⇒ Object
- #get_root_cause(symptom) ⇒ Object
-
#initialize ⇒ Registry
constructor
A new instance of Registry.
Constructor Details
#initialize ⇒ Registry
Returns a new instance of Registry.
27 28 29 30 31 32 33 |
# File 'lib/unravel.rb', line 27 def initialize @fixes = {} @symptoms = {} @achievements = {} @contexts = {} @errors = {} end |
Instance Attribute Details
#achievements ⇒ Object (readonly)
Returns the value of attribute achievements.
25 26 27 |
# File 'lib/unravel.rb', line 25 def achievements @achievements end |
#contexts ⇒ Object (readonly)
Returns the value of attribute contexts.
25 26 27 |
# File 'lib/unravel.rb', line 25 def contexts @contexts end |
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
25 26 27 |
# File 'lib/unravel.rb', line 25 def errors @errors end |
#fixes ⇒ Object (readonly)
Returns the value of attribute fixes.
25 26 27 |
# File 'lib/unravel.rb', line 25 def fixes @fixes end |
#symptoms ⇒ Object (readonly)
Returns the value of attribute symptoms.
25 26 27 |
# File 'lib/unravel.rb', line 25 def symptoms @symptoms end |
Instance Method Details
#add_achievement(name, &block) ⇒ Object
54 55 56 |
# File 'lib/unravel.rb', line 54 def add_achievement(name, &block) @achievements[name] = block end |
#add_error_contexts(name, contexts) ⇒ Object
64 65 66 |
# File 'lib/unravel.rb', line 64 def add_error_contexts(name, contexts) @contexts[name] ||= contexts end |
#add_fix(name, block) ⇒ Object
41 42 43 44 |
# File 'lib/unravel.rb', line 41 def add_fix(name, block) fail HumanInterventionNeeded, "fix already exists: #{name}" if @fixes.key?(name) @fixes[name] = block end |
#add_symptom(symptom, root_cause) ⇒ Object
50 51 52 |
# File 'lib/unravel.rb', line 50 def add_symptom(symptom, root_cause) @symptoms[symptom] = root_cause end |
#error_contexts_for_achievement(name) ⇒ Object
68 69 70 71 72 |
# File 'lib/unravel.rb', line 68 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
74 75 76 |
# File 'lib/unravel.rb', line 74 def fixable_error(name) @errors[name] end |
#get_achievement(name) ⇒ Object
58 59 60 61 62 |
# File 'lib/unravel.rb', line 58 def get_achievement(name) @achievements[name].tap do |achievement| fail HumanInterventionNeeded, "No such achievement: #{name.inspect}" unless achievement end end |
#get_fix(name) ⇒ Object
35 36 37 38 39 |
# File 'lib/unravel.rb', line 35 def get_fix(name) @fixes[name].tap do |cause| fail HumanInterventionNeeded, "No fix for: #{name}" unless cause end end |
#get_root_cause(symptom) ⇒ Object
46 47 48 |
# File 'lib/unravel.rb', line 46 def get_root_cause(symptom) @symptoms[symptom] end |