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.



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

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

Instance Attribute Details

#errorObject (readonly)

Returns the value of attribute error.



22
23
24
# File 'lib/mysql-pr/error.rb', line 22

def error
  @error
end

#sqlstateObject (readonly)

Returns the value of attribute sqlstate.



22
23
24
# File 'lib/mysql-pr/error.rb', line 22

def sqlstate
  @sqlstate
end

Class Method Details

.define_error_class(prefix_re) ⇒ Object



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

def self.define_error_class(prefix_re)
  self.constants.each do |errname|
    errname = errname.to_s
    next unless errname =~ prefix_re
    errno = self.const_get errname
    excname = errname.sub(prefix_re,'').gsub(/(\A.|_.)([A-Z]+)/){$1+$2.downcase}.gsub(/_/,'')
    klass = Class.new self
    klass.const_set 'ERRNO', errno
    self.const_set excname, klass
    self::ERROR_MAP[errno] = klass
    MysqlPR::Error.const_set errname, errno
  end
end

Instance Method Details

#errnoObject



30
31
32
# File 'lib/mysql-pr/error.rb', line 30

def errno
  self.class::ERRNO
end