Class: Gitlab::Ci::Ansi2json::State

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/ci/ansi2json/state.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(new_state, stream_size) ⇒ State

Returns a new instance of State.


11
12
13
14
15
16
17
18
# File 'lib/gitlab/ci/ansi2json/state.rb', line 11

def initialize(new_state, stream_size)
  @offset = 0
  @inherited_style = {}
  @open_sections = {}
  @stream_size = stream_size

  restore_state!(new_state)
end

Instance Attribute Details

#current_lineObject

Returns the value of attribute current_line.


9
10
11
# File 'lib/gitlab/ci/ansi2json/state.rb', line 9

def current_line
  @current_line
end

#inherited_styleObject

Returns the value of attribute inherited_style.


9
10
11
# File 'lib/gitlab/ci/ansi2json/state.rb', line 9

def inherited_style
  @inherited_style
end

#last_line_offsetObject

Returns the value of attribute last_line_offset.


9
10
11
# File 'lib/gitlab/ci/ansi2json/state.rb', line 9

def last_line_offset
  @last_line_offset
end

#offsetObject

Returns the value of attribute offset.


9
10
11
# File 'lib/gitlab/ci/ansi2json/state.rb', line 9

def offset
  @offset
end

#open_sectionsObject

Returns the value of attribute open_sections.


9
10
11
# File 'lib/gitlab/ci/ansi2json/state.rb', line 9

def open_sections
  @open_sections
end

Instance Method Details

#close_section(section, timestamp) ⇒ Object


37
38
39
40
41
42
43
44
# File 'lib/gitlab/ci/ansi2json/state.rb', line 37

def close_section(section, timestamp)
  return unless section_open?(section)

  duration = timestamp.to_i - @open_sections[section].to_i
  @current_line.set_section_duration(duration)

  @open_sections.delete(section)
end

#encodeObject


20
21
22
23
24
25
26
27
# File 'lib/gitlab/ci/ansi2json/state.rb', line 20

def encode
  state = {
    offset: @last_line_offset,
    style: @current_line.style.to_h,
    open_sections: @open_sections
  }
  Base64.urlsafe_encode64(state.to_json)
end

#new_line!(style: nil) ⇒ Object


50
51
52
53
54
55
56
57
# File 'lib/gitlab/ci/ansi2json/state.rb', line 50

def new_line!(style: nil)
  new_line = Line.new(
    offset: @offset,
    style: style || @current_line.style,
    sections: @open_sections.keys
  )
  @current_line = new_line
end

#open_section(section, timestamp, options) ⇒ Object


29
30
31
32
33
34
35
# File 'lib/gitlab/ci/ansi2json/state.rb', line 29

def open_section(section, timestamp, options)
  @open_sections[section] = timestamp

  @current_line.add_section(section)
  @current_line.set_section_options(options)
  @current_line.set_as_section_header
end

#section_open?(section) ⇒ Boolean

Returns:

  • (Boolean)

46
47
48
# File 'lib/gitlab/ci/ansi2json/state.rb', line 46

def section_open?(section)
  @open_sections.key?(section)
end

#set_last_line_offsetObject


59
60
61
# File 'lib/gitlab/ci/ansi2json/state.rb', line 59

def set_last_line_offset
  @last_line_offset = @current_line.offset
end

#update_style(commands) ⇒ Object


63
64
65
66
# File 'lib/gitlab/ci/ansi2json/state.rb', line 63

def update_style(commands)
  @current_line.flush_current_segment!
  @current_line.update_style(commands)
end