Module: COM::HResultError

Defined in:
lib/com/standarderror.rb

Overview

Sets up mappings between HRESULT errors and COM errors.

Class Method Summary collapse

Class Method Details

.define(code, error, message = nil, &block) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/com/standarderror.rb', line 42

def define(code, error, message = nil, &block)
  block = proc{ |m| m[1] } unless message or block
  COM.const_set error, Class.new(COM::Error){
    extend COM::PatternError

    pattern %r{^\s*(.*)\n\s*HRESULT\serror\scode:(0x(?i:#{code.to_s(16)}))}x

    (class << self; self; end).class_eval do
      define_method :replace do |e|
        m = pattern.match(e.message)
        new(message ? message : block.call(m))
      end
    end
  }
end