Class: OSC::Machete::Status
- Inherits:
-
Object
- Object
- OSC::Machete::Status
- Includes:
- Comparable
- Defined in:
- lib/osc/machete/status.rb
Overview
Value object representing job status independent of underlying resource manager.
All of the possible Torque statuses are not represented here. Its the responsibility of the Torque adapter (TorqueHelper) to create the appropriate Status object to represent the Torque status.
The possible values are: Undetermined, Not Submitted, Passed, Failed, Held, Queued, Running, Suspended
Instance Attribute Summary collapse
-
#char ⇒ Object
readonly
Returns the value of attribute char.
Class Method Summary collapse
-
.active_values ⇒ Array<Status>
Get an array of all the possible active Status values.
-
.completed_values ⇒ Array<Status>
Get an array of all the possible completed Status values.
- .failed ⇒ Status
- .held ⇒ Status
- .not_submitted ⇒ Status
- .passed ⇒ Status
- .queued ⇒ Status
- .running ⇒ Status
- .suspended ⇒ Status
-
.undetermined ⇒ Status
A ‘null’ special case for Status.
-
.values ⇒ Array<Status>
Get an array of all the possible Status values.
Instance Method Summary collapse
-
#+(other) ⇒ Object
Return the a StatusValue object based on the highest precedence of the two objects.
-
#<=>(other) ⇒ Integer
The comparison operator for sorting values.
-
#==(other) ⇒ Boolean
Boolean evaluation of Status object equality.
-
#active? ⇒ Boolean
True if in active state (running, queued, held, suspended).
-
#completed? ⇒ Boolean
True if in completed state (passed or failed).
-
#eql?(other) ⇒ Boolean
Boolean evaluation of Status object equality.
-
#failed? ⇒ Boolean
True if failed.
-
#hash ⇒ Fixnum
Return a hash based on the char value of the object.
-
#held? ⇒ Boolean
True if held.
-
#initialize(char) ⇒ Status
constructor
A new instance of Status.
-
#not_submitted? ⇒ Boolean
True if not_submitted.
-
#passed? ⇒ Boolean
True if passed.
-
#precedence ⇒ Integer
Return the ordinal position of the status in the precidence list.
-
#queued? ⇒ Boolean
True if queued.
-
#running? ⇒ Boolean
True if running.
-
#submitted? ⇒ Boolean
True if submitted.
-
#suspended? ⇒ Boolean
True if suspended.
-
#to_s ⇒ String
Return a readable string of the status.
-
#undetermined? ⇒ Boolean
True if undetermined.
Constructor Details
#initialize(char) ⇒ Status
Returns a new instance of Status.
130 131 132 133 134 135 136 137 |
# File 'lib/osc/machete/status.rb', line 130 def initialize(char) # char could be a status object or a string @char = (char.respond_to?(:char) ? char.char : char).to_s.upcase @char = nil if @char.empty? # if invalid status value char, default to undetermined @char = self.class.undetermined.char unless VALUES_HASH.has_key?(@char) end |
Instance Attribute Details
#char ⇒ Object (readonly)
Returns the value of attribute char.
12 13 14 |
# File 'lib/osc/machete/status.rb', line 12 def char @char end |
Class Method Details
.active_values ⇒ Array<Status>
Get an array of all the possible active Status values
46 47 48 |
# File 'lib/osc/machete/status.rb', line 46 def self.active_values values.select(&:active?) end |
.completed_values ⇒ Array<Status>
Get an array of all the possible completed Status values
53 54 55 |
# File 'lib/osc/machete/status.rb', line 53 def self.completed_values values.select(&:completed?) end |
.failed ⇒ Status
94 95 96 97 98 |
# File 'lib/osc/machete/status.rb', line 94 VALUES_HASH.each do |char, name| define_method(name) do OSC::Machete::Status.new(char) end end |
.held ⇒ Status
94 95 96 97 98 |
# File 'lib/osc/machete/status.rb', line 94 VALUES_HASH.each do |char, name| define_method(name) do OSC::Machete::Status.new(char) end end |
.not_submitted ⇒ Status
94 95 96 97 98 |
# File 'lib/osc/machete/status.rb', line 94 VALUES_HASH.each do |char, name| define_method(name) do OSC::Machete::Status.new(char) end end |
.passed ⇒ Status
94 95 96 97 98 |
# File 'lib/osc/machete/status.rb', line 94 VALUES_HASH.each do |char, name| define_method(name) do OSC::Machete::Status.new(char) end end |
.queued ⇒ Status
94 95 96 97 98 |
# File 'lib/osc/machete/status.rb', line 94 VALUES_HASH.each do |char, name| define_method(name) do OSC::Machete::Status.new(char) end end |
.running ⇒ Status
94 95 96 97 98 |
# File 'lib/osc/machete/status.rb', line 94 VALUES_HASH.each do |char, name| define_method(name) do OSC::Machete::Status.new(char) end end |
.suspended ⇒ Status
94 95 96 97 98 |
# File 'lib/osc/machete/status.rb', line 94 VALUES_HASH.each do |char, name| define_method(name) do OSC::Machete::Status.new(char) end end |
.undetermined ⇒ Status
A ‘null’ special case for Status
94 95 96 97 98 |
# File 'lib/osc/machete/status.rb', line 94 VALUES_HASH.each do |char, name| define_method(name) do OSC::Machete::Status.new(char) end end |
.values ⇒ Array<Status>
Get an array of all the possible Status values
39 40 41 |
# File 'lib/osc/machete/status.rb', line 39 def self.values VALUES.map{ |v| OSC::Machete::Status.new(v.first) } end |
Instance Method Details
#+(other) ⇒ Object
Return the a StatusValue object based on the highest precedence of the two objects.
Return [OSC::Machete::Status] The max status by precedence
171 172 173 |
# File 'lib/osc/machete/status.rb', line 171 def +(other) [self, other].max end |
#<=>(other) ⇒ Integer
The comparison operator for sorting values.
178 179 180 |
# File 'lib/osc/machete/status.rb', line 178 def <=>(other) precedence <=> other.precedence end |
#==(other) ⇒ Boolean
Boolean evaluation of Status object equality.
193 194 195 |
# File 'lib/osc/machete/status.rb', line 193 def ==(other) self.eql?(other) end |
#active? ⇒ Boolean
Returns true if in active state (running, queued, held, suspended).
145 146 147 |
# File 'lib/osc/machete/status.rb', line 145 def active? running? || queued? || held? || suspended? end |
#completed? ⇒ Boolean
Returns true if in completed state (passed or failed).
150 151 152 |
# File 'lib/osc/machete/status.rb', line 150 def completed? passed? || failed? end |
#eql?(other) ⇒ Boolean
Boolean evaluation of Status object equality.
185 186 187 188 |
# File 'lib/osc/machete/status.rb', line 185 def eql?(other) # compare Status to Status OR "C" to Status (other.respond_to?(:char) ? other.char : other) == char end |
#failed? ⇒ Boolean
Returns true if failed.
|
|
# File 'lib/osc/machete/status.rb', line 107
|
#hash ⇒ Fixnum
Return a hash based on the char value of the object.
200 201 202 |
# File 'lib/osc/machete/status.rb', line 200 def hash @char.hash end |
#held? ⇒ Boolean
Returns true if held.
|
|
# File 'lib/osc/machete/status.rb', line 113
|
#not_submitted? ⇒ Boolean
Returns true if not_submitted.
|
|
# File 'lib/osc/machete/status.rb', line 104
|
#passed? ⇒ Boolean
Returns true if passed.
|
|
# File 'lib/osc/machete/status.rb', line 110
|
#precedence ⇒ Integer
Return the ordinal position of the status in the precidence list
207 208 209 210 |
# File 'lib/osc/machete/status.rb', line 207 def precedence # Hashes enumerate their values in the order that the corresponding keys were inserted PRECEDENCE.index(@char) end |
#queued? ⇒ Boolean
Returns true if queued.
|
|
# File 'lib/osc/machete/status.rb', line 116
|
#running? ⇒ Boolean
Returns true if running.
|
|
# File 'lib/osc/machete/status.rb', line 119
|
#submitted? ⇒ Boolean
Returns true if submitted.
140 141 142 |
# File 'lib/osc/machete/status.rb', line 140 def submitted? ! (not_submitted? || undetermined?) end |
#suspended? ⇒ Boolean
Returns true if suspended.
124 125 126 127 128 |
# File 'lib/osc/machete/status.rb', line 124 VALUES_HASH.each do |char, name| define_method("#{name}?") do self == OSC::Machete::Status.new(char) end end |
#to_s ⇒ String
Return a readable string of the status
160 161 162 163 |
# File 'lib/osc/machete/status.rb', line 160 def to_s # FIXME: ActiveSupport replace with .humanize and simpler datastructure VALUES_HASH[@char].split("_").map(&:capitalize).join(" ") end |
#undetermined? ⇒ Boolean
Returns true if undetermined.
|
|
# File 'lib/osc/machete/status.rb', line 101
|