Class: Deadpool::State

Inherits:
Object
  • Object
show all
Defined in:
lib/deadpool/state.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_messagesObject (readonly)

Returns the value of attribute all_messages.



8
9
10
# File 'lib/deadpool/state.rb', line 8

def all_messages
  @all_messages
end

#error_messagesObject (readonly)

Returns the value of attribute error_messages.



8
9
10
# File 'lib/deadpool/state.rb', line 8

def error_messages
  @error_messages
end

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'lib/deadpool/state.rb', line 8

def name
  @name
end

#status_codeObject (readonly)

Returns the value of attribute status_code.



8
9
10
# File 'lib/deadpool/state.rb', line 8

def status_code
  @status_code
end

#timestampObject (readonly)

Returns the value of attribute timestamp.



8
9
10
# File 'lib/deadpool/state.rb', line 8

def timestamp
  @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 add_error_message(message)
  unless @locked
    @timestamp = Time.now
    @error_messages << message
    # @all_messages << message
  end
end

#add_message(message) ⇒ Object



62
63
64
65
66
67
# File 'lib/deadpool/state.rb', line 62

def add_message(message)
  unless @locked
    @timestamp = Time.now
    @all_messages << message
  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

#lockObject



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!(message=nil)
  unless @locked
    @timestamp      = Time.now
    @status_code    = OK
    @error_messages = []
    @all_messages   = message.nil? ? [] : [message]
  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, message)
  unless @locked
    if code == OK
      @timestamp      = Time.now
      @status_code    = OK
      @error_messages = []
      @all_messages   = [message]
    else
      @timestamp      = Time.now
      @status_code    = code
      @error_messages = [message]
      @all_messages   = []
    end
  end
end

#unlockObject



23
24
25
# File 'lib/deadpool/state.rb', line 23

def unlock
  @locked = false
end