Module: IgniterLang::TemporalAccessRuntime::Canonical

Defined in:
lib/igniter_lang/temporal_access_runtime.rb

Class Method Summary collapse

Class Method Details

.hash(value) ⇒ Object



55
56
57
# File 'lib/igniter_lang/temporal_access_runtime.rb', line 55

def hash(value)
  "sha256:#{Digest::SHA256.hexdigest(json(value))}"
end

.json(value) ⇒ Object



47
48
49
# File 'lib/igniter_lang/temporal_access_runtime.rb', line 47

def json(value)
  JSON.generate(normalize(value))
end

.normalize(value) ⇒ Object



36
37
38
39
40
41
42
43
44
45
# File 'lib/igniter_lang/temporal_access_runtime.rb', line 36

def normalize(value)
  case value
  when Hash
    value.keys.sort_by(&:to_s).each_with_object({}) { |key, out| out[key.to_s] = normalize(value[key]) }
  when Array
    value.map { |item| normalize(item) }
  else
    value
  end
end

.pretty(value) ⇒ Object



51
52
53
# File 'lib/igniter_lang/temporal_access_runtime.rb', line 51

def pretty(value)
  "#{JSON.pretty_generate(normalize(value))}\n"
end

.short_hash(value) ⇒ Object



59
60
61
# File 'lib/igniter_lang/temporal_access_runtime.rb', line 59

def short_hash(value)
  hash(value).split(":").last[0, 16]
end