class TkrzwRPC::Status

Status of operations.

Constants

APPLICATION_ERROR

Generic error caused by the application logic.

BROKEN_DATA_ERROR

Error that internal data are broken.

CANCELED_ERROR

Error that the operation is canceled.

DUPLICATION_ERROR

Error that a specific resource is duplicated.

INFEASIBLE_ERROR

Error that the operation is infeasible.

INVALID_ARGUMENT_ERROR

Error that a given argument is invalid.

NETWORK_ERROR

Error caused by networking failure.

NOT_FOUND_ERROR

Error that a specific resource is not found.

NOT_IMPLEMENTED_ERROR

Error that the feature is not implemented.

PERMISSION_ERROR

Error that the operation is not permitted.

PRECONDITION_ERROR

Error that a precondition is not met.

SUCCESS

Success.

SYSTEM_ERROR

Generic error from underlying systems.

UNKNOWN_ERROR

Generic error whose cause is unknown.

Public Class Methods

code_name(code) click to toggle source

Gets the string name of a status code.

  • @param code The status code.

  • @return The name of the status code.

# File tkrzw_rpc.rb, line 152
def self.code_name(code)
  case code
  when SUCCESS
    return "SUCCESS"
  when UNKNOWN_ERROR
    return "UNKNOWN_ERROR"
  when SYSTEM_ERROR
    return "SYSTEM_ERROR"
  when NOT_IMPLEMENTED_ERROR
    return "NOT_IMPLEMENTED_ERROR"
  when PRECONDITION_ERROR
    return "PRECONDITION_ERROR"
  when INVALID_ARGUMENT_ERROR
    return "INVALID_ARGUMENT_ERROR"
  when CANCELED_ERROR
    return "CANCELED_ERROR"
  when NOT_FOUND_ERROR
    return "NOT_FOUND_ERROR"
  when PERMISSION_ERROR
    return "PERMISSION_ERROR"
  when INFEASIBLE_ERROR
    return "INFEASIBLE_ERROR"
  when DUPLICATION_ERROR
    return "DUPLICATION_ERROR"
  when BROKEN_DATA_ERROR
    return "BROKEN_DATA_ERROR"
  when NETWORK_ERROR
    return "NETWORK_ERROR"
  when APPLICATION_ERROR
    return "APPLICATION_ERROR"
  end
  return "unknown"
end
new(code=SUCCESS, message="") click to toggle source

Sets the code and the message.

  • @param code The status code. This can be omitted and then SUCCESS is set.

  • @param message An arbitrary status message. This can be omitted and the an empty string is set.

# File tkrzw_rpc.rb, line 59
def initialize(code=SUCCESS, message="")
  @code = code
  @message = message
end

Public Instance Methods

!=(rhs) click to toggle source

Returns True if the other object doesn't have the same code.

  • @param rhs The object to compare. It can be a status or an integer.

  • @return False if they are the same, or True if they are not.

# File tkrzw_rpc.rb, line 145
def !=(rhs)
  not (self == rhs)
end
==(rhs) click to toggle source

Returns True if the other object has the same code.

  • @param rhs The object to compare. It can be a status or an integer.

  • @return True if they are the same, or False if they are not.

# File tkrzw_rpc.rb, line 132
def ==(rhs)
  if rhs.is_a?(Status)
    return @code == rhs.code
  end
  if rhs.is_a?(Integer)
    return @code == rhs
  end
  false
end
code() click to toggle source

Gets the status code.

  • @return The status code.

# File tkrzw_rpc.rb, line 83
def code
  @code
end
inspect() click to toggle source

Returns a string representation of the object.

  • @return The string representation of the object.

# File tkrzw_rpc.rb, line 125
def inspect
  "#<TkrzwRPC::Status: " + to_s + ">"
end
join(rht) click to toggle source

Assigns the internal state from another status object only if the current state is success.

  • @param rhs The status object.

# File tkrzw_rpc.rb, line 74
def join(rht)
  if @code == SUCCESS
    @code = rht.code
    @message = rht.message
  end
end
message() click to toggle source

Gets the status message.

  • @return The status message.

# File tkrzw_rpc.rb, line 89
def message
  @message
end
ok?() click to toggle source

Returns true if the status is success.

  • @return True if the status is success, or False on failure.

# File tkrzw_rpc.rb, line 95
def ok?
  @code == SUCCESS
end
or_die() click to toggle source

Raises an exception if the status is not success.

# File tkrzw_rpc.rb, line 101
def or_die
  if @code != SUCCESS
    raise StatusException.new(self)
  end
end
set(code=SUCCESS, message="") click to toggle source

Sets the code and the message.

  • @param code The status code. This can be omitted and then SUCCESS is set.

  • @param message An arbitrary status message. This can be omitted and the an empty string is set.

# File tkrzw_rpc.rb, line 67
def set(code=SUCCESS, message="")
  @code = code
  @message = message
end
to_i() click to toggle source

Returns the status code.

  • @return The status code.

# File tkrzw_rpc.rb, line 119
def to_i
  @code
end
to_s() click to toggle source

Returns a string representation of the content.

  • @return The string representation of the content.

# File tkrzw_rpc.rb, line 109
def to_s
  expr = Status.code_name(@code)
  if not @message.empty?
    expr += ": " + @message
  end
  expr
end