Module: Hashing::Hasherizer

Defined in:
lib/hashing.rb

Overview

Define the class methods that should be available in a ‘hasherized ®’ class (a class that include ‘Hashing`).

Instance Method Summary collapse

Instance Method Details

#from_hash(pairs) ⇒ Object

Receives a ‘Hash` and uses the strategy configured by `.loading` to (re)create an instance of the ’hasherized ®‘ class.

Parameters:

  • pairs (Hash)

    in a valid form defined by ‘.hasherize`

Returns:

  • new object



120
121
122
123
124
125
126
127
# File 'lib/hashing.rb', line 120

def from_hash(pairs)
   = pairs.delete(:__hashing__) || {}
  hash_to_load = pairs.map do |ivar_name, value|
    ivar = ivar_by_name ivar_name.to_sym
    [ivar.to_sym, ivar.from_hash(value, )]
  end
  strategy.call Hash[hash_to_load]
end

#ivarsArray

provides access to the current configuration on what ‘ivars` should be used to generate a `Hash` representation of instances of the client class.

Returns:

  • (Array)

    ivars that should be included in the final Hash



111
112
113
# File 'lib/hashing.rb', line 111

def ivars
  @ivars ||= []
end