Class: Decidim::FingerprintCalculator
- Inherits:
 - 
      Object
      
        
- Object
 - Decidim::FingerprintCalculator
 
 
- Defined in:
 - lib/decidim/fingerprint_calculator.rb
 
Overview
This class will generate a unique fingerprint given an arbitrarily deep hash, ensuring that the same fingerprint will be generated regardless of ordering and whether keys are symbols or strings.
Instance Method Summary collapse
- 
  
    
      #initialize(data)  ⇒ FingerprintCalculator 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    
Public: Initializes the class with a source data to be fingerprinted.
 - 
  
    
      #source  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Public: Returns the fingerprint source before hashing, so that it can be inspected by the user.
 - 
  
    
      #value  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Public: Generates a fingerprint hash.
 
Constructor Details
#initialize(data) ⇒ FingerprintCalculator
Public: Initializes the class with a source data to be fingerprinted.
      12 13 14  | 
    
      # File 'lib/decidim/fingerprint_calculator.rb', line 12 def initialize(data) @data = data end  | 
  
Instance Method Details
#source ⇒ Object
Public: Returns the fingerprint source before hashing, so that it can be inspected by the user.
Returns a String with the JSON representation of the normalized data.
      27 28 29  | 
    
      # File 'lib/decidim/fingerprint_calculator.rb', line 27 def source @source ||= JSON.generate(sort_hash(@data)) end  | 
  
#value ⇒ Object
Public: Generates a fingerprint hash.
Returns a String with the fingerprint.
      19 20 21  | 
    
      # File 'lib/decidim/fingerprint_calculator.rb', line 19 def value @value ||= Digest::SHA256.hexdigest(source) end  |