Class: ErrorToCommunicate::Config
- Inherits:
-
Object
- Object
- ErrorToCommunicate::Config
- Defined in:
- lib/error_to_communicate/config.rb
Constant Summary collapse
- DEFAULT_HEURISTICS =
[ Heuristic::WrongNumberOfArguments, Heuristic::NoMethodError, Heuristic::LoadError, Heuristic::SyntaxError, Heuristic::Exception, ]
- DEFAULT_BLACKLIST =
Should maybe also be an array, b/c there’s no great way to add a proc to the blacklist, right now, it would have to check it’s thing and then call the next one
lambda do |einfo| einfo.classname == 'SystemExit' end
Instance Attribute Summary collapse
-
#blacklist ⇒ Object
Returns the value of attribute blacklist.
-
#catchall_heuristic ⇒ Object
Returns the value of attribute catchall_heuristic.
-
#format_with ⇒ Object
Returns the value of attribute format_with.
-
#heuristics ⇒ Object
Returns the value of attribute heuristics.
-
#project ⇒ Object
Returns the value of attribute project.
-
#theme ⇒ Object
Returns the value of attribute theme.
Class Method Summary collapse
Instance Method Summary collapse
- #accept?(exception, binding) ⇒ Boolean
- #format(heuristic, cwd) ⇒ Object
- #heuristic_for(exception, binding) ⇒ Object
-
#initialize(options = {}) ⇒ Config
constructor
A new instance of Config.
Constructor Details
#initialize(options = {}) ⇒ Config
Returns a new instance of Config.
43 44 45 46 47 48 49 50 51 |
# File 'lib/error_to_communicate/config.rb', line 43 def initialize(={}) self.heuristics = .fetch(:heuristics) { DEFAULT_HEURISTICS } self.blacklist = .fetch(:blacklist) { DEFAULT_BLACKLIST } self.theme = .fetch(:theme) { Theme.new } # this is still really fkn rough self.format_with = .fetch(:format_with) { FormatTerminal } loaded_features = .fetch(:loaded_features) { $LOADED_FEATURES } root = .fetch(:root) { File. Dir.pwd } self.project = Project.new root: root, loaded_features: loaded_features end |
Instance Attribute Details
#blacklist ⇒ Object
Returns the value of attribute blacklist.
41 42 43 |
# File 'lib/error_to_communicate/config.rb', line 41 def blacklist @blacklist end |
#catchall_heuristic ⇒ Object
Returns the value of attribute catchall_heuristic.
41 42 43 |
# File 'lib/error_to_communicate/config.rb', line 41 def catchall_heuristic @catchall_heuristic end |
#format_with ⇒ Object
Returns the value of attribute format_with.
41 42 43 |
# File 'lib/error_to_communicate/config.rb', line 41 def format_with @format_with end |
#heuristics ⇒ Object
Returns the value of attribute heuristics.
41 42 43 |
# File 'lib/error_to_communicate/config.rb', line 41 def heuristics @heuristics end |
#project ⇒ Object
Returns the value of attribute project.
41 42 43 |
# File 'lib/error_to_communicate/config.rb', line 41 def project @project end |
#theme ⇒ Object
Returns the value of attribute theme.
41 42 43 |
# File 'lib/error_to_communicate/config.rb', line 41 def theme @theme end |
Class Method Details
.default ⇒ Object
37 38 39 |
# File 'lib/error_to_communicate/config.rb', line 37 def self.default @default ||= new end |
Instance Method Details
#accept?(exception, binding) ⇒ Boolean
53 54 55 56 57 |
# File 'lib/error_to_communicate/config.rb', line 53 def accept?(exception, binding) return false unless ExceptionInfo.parseable? exception, binding einfo = ExceptionInfo.parse(exception, binding) !blacklist.call(einfo) && !!heuristics.find { |h| h.for? einfo } end |
#format(heuristic, cwd) ⇒ Object
66 67 68 |
# File 'lib/error_to_communicate/config.rb', line 66 def format(heuristic, cwd) format_with.call theme: theme, heuristic: heuristic, cwd: Pathname.new(cwd) end |
#heuristic_for(exception, binding) ⇒ Object
59 60 61 62 63 64 |
# File 'lib/error_to_communicate/config.rb', line 59 def heuristic_for(exception, binding) accept?(exception, binding) || raise(ArgumentError, "Asked for a heuristic on an object we don't accept: #{exception.inspect}") einfo = ExceptionInfo.parse(exception, binding) heuristics.find { |heuristic| heuristic.for? einfo } .new(einfo: einfo, project: project) end |