class Fastbeans::Response

Public Class Methods

new(call_data, raw_response) click to toggle source
# File lib/fastbeans/response.rb, line 4
def initialize(call_data, raw_response)
  @call_data = call_data
  @raw_response = raw_response
end

Public Instance Methods

camelize(term, uppercase_first_letter = true) click to toggle source
# File lib/fastbeans/response.rb, line 42
def camelize(term, uppercase_first_letter = true)
  string = term.to_s
  acronym_regex = /(?=a)b/
  if uppercase_first_letter
    string = string.sub(/^[a-z\d]*/) { $&.capitalize }
  else
    string = string.sub(/^(?:#{acronym_regex}(?=\b|[A-Z_])|\w)/) { $&.downcase }
  end
  string.gsub(/(?:_|(\/))([a-z\d]*)/) { "#{$1}#{$2.capitalize}" }.gsub('/', '::')
end
error?() click to toggle source
# File lib/fastbeans/response.rb, line 9
def error?
  @raw_response.is_a?(Hash) and @raw_response.has_key?("fastbeans-error")
end
payload() click to toggle source
# File lib/fastbeans/response.rb, line 25
def payload
  unless error?
    @raw_response[1]
  else
    raise_exception
  end
end
raise_exception() click to toggle source
# File lib/fastbeans/response.rb, line 33
def raise_exception
  name = camelize(underscore(@raw_response["fastbeans-error"]))
  error = @raw_response["error-information"]

  msg = "%s\nCall: %s" % [error["message"], error["call"]]
  backtrace = error["backtrace"].split(/\n/).concat(caller).flatten.compact
  raise Fastbeans.exception(name), msg, backtrace
end
signature() click to toggle source
# File lib/fastbeans/response.rb, line 13
def signature
  unless error?
    @raw_response[0]
  else
    nil
  end
end
signed_with?(orig_signature) click to toggle source
# File lib/fastbeans/response.rb, line 21
def signed_with?(orig_signature)
  signature == orig_signature
end
underscore(camel_cased_word) click to toggle source
# File lib/fastbeans/response.rb, line 53
def underscore(camel_cased_word)
  word = camel_cased_word.to_s.dup
  acronym_regex = /(?=a)b/
  word.gsub!(/::/, '/')
  word.gsub!(/(?:([A-Za-z\d])|^)(#{acronym_regex})(?=\b|[^a-z])/) { "#{$1}#{$1 && '_'}#{$2.downcase}" }
  word.gsub!(/([A-Z\d]+)([A-Z][a-z])/,'\1_\2')
  word.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
  word.tr!("-", "_")
  word.gsub!(/\s+/, "_")
  word.downcase!
  word
end