Method: FeatureFlagMonitor::Utils::RestrictedHash#initialize

Defined in:
lib/feature_flag_monitor/utils/restricted_hash.rb

#initialize(hash = {}, when_not_found = FeatureFlagMonitor::FlagNotFound) ⇒ RestrictedHash

Returns a new instance of RestrictedHash.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/feature_flag_monitor/utils/restricted_hash.rb', line 26

def initialize(hash = {}, when_not_found = FeatureFlagMonitor::FlagNotFound)
  super()
  merge!(hash)

  @key_not_found = when_not_found

  each_key do |flag|
    singleton_class.class_eval do
      define_method(flag) { fetch(flag) }
    end
  end

  singleton_class.class_eval do
    MUTATION_METHODS.each do |_method|
      define_method(_method) { |*args, &block| raise MutationNotAllowed }
    end
  end
end