Exception: MysqlPR::Error

Inherits:
StandardError
  • Object
show all
Defined in:
lib/mysql-pr/error.rb

Direct Known Subclasses

ClientError, ServerError

Constant Summary collapse

ERRNO =
0

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message, sqlstate = "HY000") ⇒ Error

Returns a new instance of Error.



27
28
29
30
31
# File 'lib/mysql-pr/error.rb', line 27

def initialize(message, sqlstate = "HY000")
  @sqlstate = sqlstate
  @error = message
  super message
end

Instance Attribute Details

#errorObject (readonly)

Returns the value of attribute error.



25
26
27
# File 'lib/mysql-pr/error.rb', line 25

def error
  @error
end

#sqlstateObject (readonly)

Returns the value of attribute sqlstate.



25
26
27
# File 'lib/mysql-pr/error.rb', line 25

def sqlstate
  @sqlstate
end

Class Method Details

.define_error_class(prefix_re) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/mysql-pr/error.rb', line 10

def self.define_error_class(prefix_re)
  constants.each do |errname|
    errname = errname.to_s
    next unless errname =~ prefix_re

    errno = const_get errname
    excname = errname.sub(prefix_re, "").gsub(/(\A.|_.)([A-Z]+)/) { ::Regexp.last_match(1) + ::Regexp.last_match(2).downcase }.gsub(/_/, "")
    klass = Class.new self
    klass.const_set "ERRNO", errno
    const_set excname, klass
    self::ERROR_MAP[errno] = klass
    MysqlPR::Error.const_set errname, errno
  end
end

Instance Method Details

#errnoObject



33
34
35
# File 'lib/mysql-pr/error.rb', line 33

def errno
  self.class::ERRNO
end