Class: Gitlab::Terraform::ScHandler

Inherits:
Oj::ScHandler
  • Object
show all
Defined in:
lib/gitlab/terraform/state_parser.rb

Overview

This streaming JSON handler extracts the serial keyword from the Terraform state API. This is faster and more efficient than running ‘JSON.parse(data)[’serial’]‘ particularly for large JSON blobs.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeScHandler

Returns a new instance of ScHandler.



11
12
13
14
# File 'lib/gitlab/terraform/state_parser.rb', line 11

def initialize
  @serial = nil
  @depth = 0
end

Instance Attribute Details

#serialObject (readonly)

Returns the value of attribute serial.



9
10
11
# File 'lib/gitlab/terraform/state_parser.rb', line 9

def serial
  @serial
end

Instance Method Details

#hash_endObject



20
21
22
# File 'lib/gitlab/terraform/state_parser.rb', line 20

def hash_end
  @depth -= 1
end

#hash_set(_hash, key, value) ⇒ Object



24
25
26
27
28
# File 'lib/gitlab/terraform/state_parser.rb', line 24

def hash_set(_hash, key, value)
  return unless @depth == 1 && key == 'serial'

  @serial = value
end

#hash_startObject



16
17
18
# File 'lib/gitlab/terraform/state_parser.rb', line 16

def hash_start
  @depth += 1
end