Exception: ThreeScale::Core::Error

Inherits:
RuntimeError
  • Object
show all
Defined in:
lib/3scale/core/errors.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.codeObject



18
19
20
# File 'lib/3scale/core/errors.rb', line 18

def self.code
  underscore(name[/[^:]*$/])
end

.underscore(string) ⇒ Object

TODO: move this over to some utility module.



23
24
25
26
27
28
# File 'lib/3scale/core/errors.rb', line 23

def self.underscore(string)
  # Code stolen from ActiveSupport
  string.gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
         gsub(/([a-z\d])([A-Z])/,'\1_\2').
         downcase
end

Instance Method Details

#codeObject



14
15
16
# File 'lib/3scale/core/errors.rb', line 14

def code
  self.class.code
end

#to_xml(options = {}) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/3scale/core/errors.rb', line 6

def to_xml(options = {})
  xml = Builder::XmlMarkup.new
  xml.instruct! unless options[:skip_instruct]
  xml.error(message, :code => code)

  xml.target!
end