Class: Encode::Encoder

Inherits:
Object
  • Object
show all
Defined in:
lib/object_hash_rb/encode.rb

Overview

Performs encoding while managing state.

Instance Method Summary collapse

Constructor Details

#initialize(replacer: nil, unordered_objects: true) ⇒ Encoder

When initializing, you can provide options to modify how the encoder functions.



134
135
136
137
138
139
140
141
# File 'lib/object_hash_rb/encode.rb', line 134

def initialize(replacer: nil, unordered_objects: true)
  # OPTIONS
  @replacer = replacer
  @unordered_objects = unordered_objects

  # Used for circular reference handling.
  @context = []
end

Instance Method Details

#encode_cleanupObject



143
144
145
# File 'lib/object_hash_rb/encode.rb', line 143

def encode_cleanup
  @context = []
end

#perform_encode(input) ⇒ Object

@INTERNAL: Please use ObjectHash.hash() instead. Encodes the input value to match a standardized format.



149
150
151
152
153
154
155
156
157
158
# File 'lib/object_hash_rb/encode.rb', line 149

def perform_encode(input)
  # Encode the value.
  result = encode_value(input)

  # Cleanup.
  encode_cleanup

  # Return the encoded value.
  result
end