Class: Gitlab::Ci::Ansi2json::State
- Inherits:
-
Object
- Object
- Gitlab::Ci::Ansi2json::State
- Defined in:
- lib/gitlab/ci/ansi2json/state.rb
Instance Attribute Summary collapse
-
#current_line ⇒ Object
Returns the value of attribute current_line.
-
#inherited_style ⇒ Object
Returns the value of attribute inherited_style.
-
#last_line_offset ⇒ Object
Returns the value of attribute last_line_offset.
-
#offset ⇒ Object
Returns the value of attribute offset.
-
#open_sections ⇒ Object
Returns the value of attribute open_sections.
Instance Method Summary collapse
- #close_section(section, timestamp) ⇒ Object
- #encode ⇒ Object
-
#initialize(new_state, stream_size) ⇒ State
constructor
A new instance of State.
- #new_line!(style: nil) ⇒ Object
- #open_section(section, timestamp) ⇒ Object
- #section_open?(section) ⇒ Boolean
- #set_last_line_offset ⇒ Object
- #update_style(commands) ⇒ Object
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_line ⇒ Object
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_style ⇒ Object
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_offset ⇒ Object
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 |
#offset ⇒ Object
Returns the value of attribute offset
9 10 11 |
# File 'lib/gitlab/ci/ansi2json/state.rb', line 9 def offset @offset end |
#open_sections ⇒ Object
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, ) return unless section_open?(section) duration = .to_i - @open_sections[section].to_i @current_line.set_section_duration(duration) @open_sections.delete(section) end |
#encode ⇒ Object
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, ) @open_sections[section] = @current_line.add_section(section) @current_line.set_as_section_header end |
#section_open?(section) ⇒ 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_offset ⇒ Object
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 |