Module: Otto::Core::Freezable

Included in:
Configuration, MiddlewareStack, Locale::Config, Privacy::Config, Security::Config
Defined in:
lib/otto/core/freezable.rb

Overview

Provides deep freezing capability for configuration objects

This module enables objects to be deeply frozen, preventing any modifications to the object itself and all its nested structures. This is critical for security as it prevents runtime tampering with security configurations.

Examples:

class MyConfig
  include Otto::Core::Freezable

  def initialize
    @settings = { security: { enabled: true } }
  end
end

config = MyConfig.new
config.deep_freeze!
# Now config and all nested hashes/arrays are frozen

Instance Method Summary collapse

Instance Method Details

#deep_freeze!self

Deeply freeze this object and all its instance variables

This method recursively freezes all nested structures including:

  • Hashes (both keys and values)

  • Arrays (and all elements)

  • Sets

  • Other freezable objects

NOTE: This method is idempotent and safe to call multiple times.

Returns:

  • (self)

    The frozen object



39
40
41
42
43
44
45
# File 'lib/otto/core/freezable.rb', line 39

def deep_freeze!
  return self if frozen?

  freeze_instance_variables!
  freeze
  self
end