Class: Gitlab::Ci::Ansi2json::State
- Inherits:
-
Object
- Object
- Gitlab::Ci::Ansi2json::State
- Includes:
- Utils::StrongMemoize
- Defined in:
- lib/gitlab/ci/ansi2json/state.rb
Constant Summary collapse
- SIGNATURE_KEY_SALT =
'gitlab-ci-ansi2json-state'
- SEPARATOR =
'--'
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, options) ⇒ 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.
18 19 20 21 22 23 24 25 |
# File 'lib/gitlab/ci/ansi2json/state.rb', line 18 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.
16 17 18 |
# File 'lib/gitlab/ci/ansi2json/state.rb', line 16 def current_line @current_line end |
#inherited_style ⇒ Object
Returns the value of attribute inherited_style.
16 17 18 |
# File 'lib/gitlab/ci/ansi2json/state.rb', line 16 def inherited_style @inherited_style end |
#last_line_offset ⇒ Object
Returns the value of attribute last_line_offset.
16 17 18 |
# File 'lib/gitlab/ci/ansi2json/state.rb', line 16 def last_line_offset @last_line_offset end |
#offset ⇒ Object
Returns the value of attribute offset.
16 17 18 |
# File 'lib/gitlab/ci/ansi2json/state.rb', line 16 def offset @offset end |
#open_sections ⇒ Object
Returns the value of attribute open_sections.
16 17 18 |
# File 'lib/gitlab/ci/ansi2json/state.rb', line 16 def open_sections @open_sections end |
Instance Method Details
#close_section(section, timestamp) ⇒ Object
47 48 49 50 51 52 53 54 |
# File 'lib/gitlab/ci/ansi2json/state.rb', line 47 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
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/gitlab/ci/ansi2json/state.rb', line 27 def encode json = { offset: @last_line_offset, style: @current_line.style.to_h, open_sections: @open_sections }.to_json encoded = Base64.urlsafe_encode64(json, padding: false) encoded + SEPARATOR + sign(encoded) end |
#new_line!(style: nil) ⇒ Object
60 61 62 63 64 65 66 67 |
# File 'lib/gitlab/ci/ansi2json/state.rb', line 60 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
39 40 41 42 43 44 45 |
# File 'lib/gitlab/ci/ansi2json/state.rb', line 39 def open_section(section, , ) @open_sections[section] = @current_line.add_section(section) @current_line.() @current_line.set_as_section_header end |
#section_open?(section) ⇒ Boolean
56 57 58 |
# File 'lib/gitlab/ci/ansi2json/state.rb', line 56 def section_open?(section) @open_sections.key?(section) end |
#set_last_line_offset ⇒ Object
69 70 71 |
# File 'lib/gitlab/ci/ansi2json/state.rb', line 69 def set_last_line_offset @last_line_offset = @current_line.offset end |
#update_style(commands) ⇒ Object
73 74 75 76 |
# File 'lib/gitlab/ci/ansi2json/state.rb', line 73 def update_style(commands) @current_line.flush_current_segment! @current_line.update_style(commands) end |