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


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

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


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

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) ⇒ Object


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

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

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

#section_open?(section) ⇒ Boolean

Returns:

  • (Boolean)

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

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

#set_last_line_offsetObject


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

def set_last_line_offset
  @last_line_offset = @current_line.offset
end

#update_style(commands) ⇒ Object


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

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