Class: Gitlab::Terraform::ScHandler
- Inherits:
-
Oj::ScHandler
- Object
- Oj::ScHandler
- Gitlab::Terraform::ScHandler
- 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
-
#serial ⇒ Object
readonly
Returns the value of attribute serial.
Instance Method Summary collapse
- #hash_end ⇒ Object
- #hash_set(_hash, key, value) ⇒ Object
- #hash_start ⇒ Object
-
#initialize ⇒ ScHandler
constructor
A new instance of ScHandler.
Constructor Details
#initialize ⇒ ScHandler
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
#serial ⇒ Object (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_end ⇒ Object
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_start ⇒ Object
16 17 18 |
# File 'lib/gitlab/terraform/state_parser.rb', line 16 def hash_start @depth += 1 end |