Class: SmartCore::Schema::Checker::VerifiableHash Private

Inherits:
Object
  • Object
show all
Defined in:
lib/smart_core/schema/checker/verifiable_hash.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Since:

  • 0.1.0

Version:

  • 0.8.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

  • source (Hash<String|Symbol,Any>)

Since:

  • 0.1.0



18
19
20
# File 'lib/smart_core/schema/checker/verifiable_hash.rb', line 18

def initialize(source)
  @source = source
end

Instance Attribute Details

#sourceHash<String|Symbol,Any> (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Hash<String|Symbol,Any>)

Since:

  • 0.1.0



11
12
13
# File 'lib/smart_core/schema/checker/verifiable_hash.rb', line 11

def source
  @source
end

Instance Method Details

#extract(key) ⇒ SmartCore::Schema::Checker::VerifiableHash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

  • key (String)

Returns:

Since:

  • 0.8.0



27
28
29
# File 'lib/smart_core/schema/checker/verifiable_hash.rb', line 27

def extract(key)
  SmartCore::Schema::Checker::VerifiableHash.new(fetch(key))
end

#fetch(key) ⇒ Any Also known as: []

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

  • key (String)

Returns:

  • (Any)

Since:

  • 0.1.0

Version:

  • 0.8.0



56
57
58
59
60
61
62
63
# File 'lib/smart_core/schema/checker/verifiable_hash.rb', line 56

def fetch(key)
  # @note
  #   Previously we used exceptional flow "hash.fetch(key) rescue hash.fetch(key.to_sym)".
  #   This flow can generate a lot of useless objects during rescuable `KeyError` exception
  #   (useless error messages, backtraces, etc, object that was silently suppressed).
  #   So, the "if"-#key?-oriented flow is better (generates fewer number of objects statistically)
  source.key?(key) ? source.fetch(key) : source.fetch(key.to_sym)
end

#key?(key) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

  • key (String)

Returns:

  • (Boolean)

Since:

  • 0.1.0

Version:

  • 0.8.0



46
47
48
# File 'lib/smart_core/schema/checker/verifiable_hash.rb', line 46

def key?(key)
  source.key?(key) || source.key?(key.to_sym)
end

#keysArray<String>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Array<String>)

Since:

  • 0.1.0

Version:

  • 0.8.0



36
37
38
# File 'lib/smart_core/schema/checker/verifiable_hash.rb', line 36

def keys
  SmartCore::Schema::KeyControl.normalize_list(source.keys)
end