Class: Bricolage::JobResult
- Inherits:
-
Object
- Object
- Bricolage::JobResult
- Defined in:
- lib/bricolage/jobresult.rb
Constant Summary collapse
- EXIT_SUCCESS =
0
- EXIT_FAILURE =
production time errors; expected / unavoidable job error
1
- EXIT_ERROR =
development time errors (e.g. bad option, bad parameter, bad configuration)
2
Instance Attribute Summary collapse
-
#exception ⇒ Object
readonly
Returns the value of attribute exception.
-
#process_status ⇒ Object
readonly
Returns the value of attribute process_status.
Class Method Summary collapse
- .error(ex) ⇒ Object
- .failure(ex) ⇒ Object
- .for_bool(is_success, msg = nil) ⇒ Object
- .for_process_status(st, msg = nil) ⇒ Object
- .success ⇒ Object
Instance Method Summary collapse
-
#initialize(type, exception: nil, process_status: nil, message: nil) ⇒ JobResult
constructor
A new instance of JobResult.
- #message ⇒ Object
- #status ⇒ Object (also: #to_i)
- #status_string ⇒ Object
- #success? ⇒ Boolean
Constructor Details
#initialize(type, exception: nil, process_status: nil, message: nil) ⇒ JobResult
Returns a new instance of JobResult.
30 31 32 33 34 35 |
# File 'lib/bricolage/jobresult.rb', line 30 def initialize(type, exception: nil, process_status: nil, message: nil) @type = type @exception = exception @process_status = process_status @message = end |
Instance Attribute Details
#exception ⇒ Object (readonly)
Returns the value of attribute exception.
41 42 43 |
# File 'lib/bricolage/jobresult.rb', line 41 def exception @exception end |
#process_status ⇒ Object (readonly)
Returns the value of attribute process_status.
42 43 44 |
# File 'lib/bricolage/jobresult.rb', line 42 def process_status @process_status end |
Class Method Details
.error(ex) ⇒ Object
14 15 16 |
# File 'lib/bricolage/jobresult.rb', line 14 def JobResult.error(ex) new(:error, exception: ex) end |
.failure(ex) ⇒ Object
10 11 12 |
# File 'lib/bricolage/jobresult.rb', line 10 def JobResult.failure(ex) new(:failiure, exception: ex) end |
.for_bool(is_success, msg = nil) ⇒ Object
18 19 20 |
# File 'lib/bricolage/jobresult.rb', line 18 def JobResult.for_bool(is_success, msg = nil) new((is_success ? :success : :failure), message: msg) end |
.for_process_status(st, msg = nil) ⇒ Object
22 23 24 |
# File 'lib/bricolage/jobresult.rb', line 22 def JobResult.for_process_status(st, msg = nil) new((st.success? ? :success : :failure), process_status: st, message: msg) end |
.success ⇒ Object
6 7 8 |
# File 'lib/bricolage/jobresult.rb', line 6 def JobResult.success new(:success) end |
Instance Method Details
#message ⇒ Object
64 65 66 67 68 69 70 71 72 |
# File 'lib/bricolage/jobresult.rb', line 64 def if @message @message elsif @exception @exception. else success? ? 'suceeded' : 'failed' end end |
#status ⇒ Object Also known as: to_i
48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/bricolage/jobresult.rb', line 48 def status if @process_status # Process::Status#exitstatus may be nil when the command did not exited normally @process_status.exitstatus || EXIT_FAILURE else case @type when :success then EXIT_SUCCESS when :failure then EXIT_FAILURE when :error then EXIT_ERROR else EXIT_ERROR end end end |
#status_string ⇒ Object
44 45 46 |
# File 'lib/bricolage/jobresult.rb', line 44 def status_string @type.to_s.upcase end |
#success? ⇒ Boolean
37 38 39 |
# File 'lib/bricolage/jobresult.rb', line 37 def success? @type == :success end |