Sha256: 4921878b7741cdb26e5173b4d18fc19f45bb5f09052d9dfbfab1640938604171

Contents?: true

Size: 1.23 KB

Versions: 12

Compression:

Stored size: 1.23 KB

Contents

# encoding: utf-8

module IceNine
  class Freezer

    # A freezer class for handling Hash objects
    class Hash < Object

      # Deep Freeze a Hash
      #
      # @example
      #   hash = IceNine::Freezer::Hash.deep_freeze('a' => '1', 'b' => '2')
      #   hash.keys.select(&:frozen?)    # => ['a', 'b']
      #   hash.values.select(&:frozen?)  # => ['1', '2']
      #
      # @param [Hash] hash
      # @param [RecursionGuard] recursion_guard
      #
      # @return [Hash]
      def self.guarded_deep_freeze(hash, recursion_guard)
        super
        default = hash.default_proc || hash.default
        Freezer.guarded_deep_freeze(default, recursion_guard)
        freeze_key_value_pairs(hash, recursion_guard)
      end

      # Handle freezing the key/value pairs
      #
      # @param [Hash] hash
      # @param [RecursionGuard] recursion_guard
      #
      # @return [undefined]
      #
      # @api private
      def self.freeze_key_value_pairs(hash, recursion_guard)
        hash.each do |key, value|
          Freezer.guarded_deep_freeze(key, recursion_guard)
          Freezer.guarded_deep_freeze(value, recursion_guard)
        end
      end

      private_class_method :freeze_key_value_pairs

    end # Hash
  end # Freezer
end # IceNine

Version data entries

12 entries across 10 versions & 4 rubygems

Version Path
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/ice_nine-0.11.2/lib/ice_nine/freezer/hash.rb
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/ice_nine-0.11.2/lib/ice_nine/freezer/hash.rb
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/ice_nine-0.11.2/lib/ice_nine/freezer/hash.rb
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/ice_nine-0.11.2/lib/ice_nine/freezer/hash.rb
grape-extra_validators-1.0.0 vendor/bundle/ruby/2.4.0/gems/ice_nine-0.11.2/lib/ice_nine/freezer/hash.rb
config_gems_initialization_aim-0.1.4 vendor/bundle/ruby/2.5.0/gems/ice_nine-0.11.2/lib/ice_nine/freezer/hash.rb
config_gems_initialization_aim-0.1.4 vendor/bundle/ruby/2.5.0/gems/config_gems_initialization_aim-0.1.1/vendor/bundle/ruby/2.5.0/gems/ice_nine-0.11.2/lib/ice_nine/freezer/hash.rb
config_gems_initialization_aim-0.1.3 vendor/bundle/ruby/2.5.0/gems/ice_nine-0.11.2/lib/ice_nine/freezer/hash.rb
config_gems_initialization_aim-0.1.3 vendor/bundle/ruby/2.5.0/gems/config_gems_initialization_aim-0.1.1/vendor/bundle/ruby/2.5.0/gems/ice_nine-0.11.2/lib/ice_nine/freezer/hash.rb
ice_nine-0.11.2 lib/ice_nine/freezer/hash.rb
ice_nine-0.11.1 lib/ice_nine/freezer/hash.rb
ice_nine-0.11.0 lib/ice_nine/freezer/hash.rb