Class: Deadpool::State
- Inherits:
-
Object
- Object
- Deadpool::State
- Defined in:
- lib/deadpool/state.rb
Instance Attribute Summary collapse
-
#all_messages ⇒ Object
readonly
Returns the value of attribute all_messages.
-
#error_messages ⇒ Object
readonly
Returns the value of attribute error_messages.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#status_code ⇒ Object
readonly
Returns the value of attribute status_code.
-
#timestamp ⇒ Object
readonly
Returns the value of attribute timestamp.
Instance Method Summary collapse
- #add_error_message(message) ⇒ Object
- #add_message(message) ⇒ Object
- #escalate_status_code(code) ⇒ Object
-
#initialize(name, klass = '') ⇒ State
constructor
A new instance of State.
- #lock ⇒ Object
- #reset!(message = nil) ⇒ Object
- #set_state(code, message) ⇒ Object
- #unlock ⇒ Object
Constructor Details
#initialize(name, klass = '') ⇒ State
Returns a new instance of State.
10 11 12 13 14 15 16 17 |
# File 'lib/deadpool/state.rb', line 10 def initialize(name, klass='') names = [] names << name unless (name.nil? and name.blank?) names << klass.to_s unless (klass.nil? and klass.blank?) @name = names.join " - " @locked = false reset! end |
Instance Attribute Details
#all_messages ⇒ Object (readonly)
Returns the value of attribute all_messages.
8 9 10 |
# File 'lib/deadpool/state.rb', line 8 def @all_messages end |
#error_messages ⇒ Object (readonly)
Returns the value of attribute error_messages.
8 9 10 |
# File 'lib/deadpool/state.rb', line 8 def @error_messages end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
8 9 10 |
# File 'lib/deadpool/state.rb', line 8 def name @name end |
#status_code ⇒ Object (readonly)
Returns the value of attribute status_code.
8 9 10 |
# File 'lib/deadpool/state.rb', line 8 def status_code @status_code end |
#timestamp ⇒ Object (readonly)
Returns the value of attribute timestamp.
8 9 10 |
# File 'lib/deadpool/state.rb', line 8 def @timestamp end |
Instance Method Details
#add_error_message(message) ⇒ Object
69 70 71 72 73 74 75 |
# File 'lib/deadpool/state.rb', line 69 def () unless @locked @timestamp = Time.now @error_messages << # @all_messages << message end end |
#add_message(message) ⇒ Object
62 63 64 65 66 67 |
# File 'lib/deadpool/state.rb', line 62 def () unless @locked @timestamp = Time.now @all_messages << end end |
#escalate_status_code(code) ⇒ Object
52 53 54 55 56 57 58 59 60 |
# File 'lib/deadpool/state.rb', line 52 def escalate_status_code(code) unless @locked @timestamp = Time.now if code >= @status_code @status_code = code end end end |
#lock ⇒ Object
19 20 21 |
# File 'lib/deadpool/state.rb', line 19 def lock @locked = true end |
#reset!(message = nil) ⇒ Object
43 44 45 46 47 48 49 50 |
# File 'lib/deadpool/state.rb', line 43 def reset!(=nil) unless @locked @timestamp = Time.now @status_code = OK @error_messages = [] @all_messages = .nil? ? [] : [] end end |
#set_state(code, message) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/deadpool/state.rb', line 27 def set_state(code, ) unless @locked if code == OK @timestamp = Time.now @status_code = OK @error_messages = [] @all_messages = [] else @timestamp = Time.now @status_code = code @error_messages = [] @all_messages = [] end end end |
#unlock ⇒ Object
23 24 25 |
# File 'lib/deadpool/state.rb', line 23 def unlock @locked = false end |