Class: DigestHash
- Inherits:
-
Object
- Object
- DigestHash
- Defined in:
- lib/digest_hash.rb
Class Method Summary collapse
Instance Method Summary collapse
- #cache_key ⇒ Object
- #cleaned_params ⇒ Object
- #deeply_sort_and_stringify_values ⇒ Object
-
#initialize(params) ⇒ DigestHash
constructor
A new instance of DigestHash.
- #remove_nulls ⇒ Object
- #sort_and_stringify_hash ⇒ Object
- #stringify_keys ⇒ Object
Constructor Details
#initialize(params) ⇒ DigestHash
Returns a new instance of DigestHash.
9 10 11 |
# File 'lib/digest_hash.rb', line 9 def initialize(params) @params = params end |
Class Method Details
.call(params) ⇒ Object
5 6 7 |
# File 'lib/digest_hash.rb', line 5 def self.call(params) new(params).cache_key end |
Instance Method Details
#cache_key ⇒ Object
13 14 15 |
# File 'lib/digest_hash.rb', line 13 def cache_key Digest::MD5.hexdigest(cleaned_params) end |
#cleaned_params ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/digest_hash.rb', line 17 def cleaned_params @cleaned_params = @params remove_nulls deeply_sort_and_stringify_values stringify_keys sort_and_stringify_hash end |
#deeply_sort_and_stringify_values ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/digest_hash.rb', line 32 def deeply_sort_and_stringify_values @cleaned_params = @cleaned_params.deep_merge(@cleaned_params) do |_, _, val| if val.is_a? Array val.sort.to_s else val.to_s end end end |
#remove_nulls ⇒ Object
26 27 28 29 30 |
# File 'lib/digest_hash.rb', line 26 def remove_nulls @cleaned_params = @cleaned_params.to_h.delete_if do |_, val| val.nil? || val.try(:empty?) end end |
#sort_and_stringify_hash ⇒ Object
46 47 48 |
# File 'lib/digest_hash.rb', line 46 def sort_and_stringify_hash @cleaned_params = @cleaned_params.sort.to_s end |
#stringify_keys ⇒ Object
42 43 44 |
# File 'lib/digest_hash.rb', line 42 def stringify_keys @cleaned_params = @cleaned_params.deep_stringify_keys end |