Class: HP::Cloud::CliStatus
- Inherits:
-
Object
- Object
- HP::Cloud::CliStatus
- Defined in:
- lib/hpcloud/cli_status.rb
Constant Summary collapse
- TYPES =
{ :success => 0, :general_error => 1, :not_supported => 3, :not_found => 4, :conflicted => 5, :incorrect_usage => 64, :permission_denied => 77, :rate_limited => 88, :partial_error => 98, :unknown_status => 99 }
Instance Attribute Summary collapse
-
#error_code ⇒ Object
Returns the value of attribute error_code.
-
#exit_code ⇒ Object
Returns the value of attribute exit_code.
-
#message ⇒ Object
Returns the value of attribute message.
Instance Method Summary collapse
- #get ⇒ Object
-
#initialize(message = nil, code = :success) ⇒ CliStatus
constructor
A new instance of CliStatus.
- #is_success? ⇒ Boolean
- #set(code) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(message = nil, code = :success) ⇒ CliStatus
Returns a new instance of CliStatus.
39 40 41 42 43 44 |
# File 'lib/hpcloud/cli_status.rb', line 39 def initialize( = nil, code = :success) @message = @error_code = :success @exit_code = 0 set(code) end |
Instance Attribute Details
#error_code ⇒ Object
Returns the value of attribute error_code.
25 26 27 |
# File 'lib/hpcloud/cli_status.rb', line 25 def error_code @error_code end |
#exit_code ⇒ Object
Returns the value of attribute exit_code.
25 26 27 |
# File 'lib/hpcloud/cli_status.rb', line 25 def exit_code @exit_code end |
#message ⇒ Object
Returns the value of attribute message.
25 26 27 |
# File 'lib/hpcloud/cli_status.rb', line 25 def @message end |
Instance Method Details
#get ⇒ Object
71 72 73 |
# File 'lib/hpcloud/cli_status.rb', line 71 def get return @exit_code end |
#is_success? ⇒ Boolean
67 68 69 |
# File 'lib/hpcloud/cli_status.rb', line 67 def is_success? return @error_code == :success end |
#set(code) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/hpcloud/cli_status.rb', line 46 def set(code) unless code.is_a?(Symbol) if code.is_a?(CliStatus) @message = code. code = code.error_code else warn "Incorrect error code: #{code.to_s}" code = :unknown_status end end exit_code = TYPES[code] if exit_code.nil? warn "Unknown error code: #{code.to_s}" exit_code = TYPES[:unknown_status] end if exit_code > @exit_code @error_code = code @exit_code = exit_code end end |
#to_s ⇒ Object
75 76 77 |
# File 'lib/hpcloud/cli_status.rb', line 75 def to_s return @message.to_s end |