Sha256: 0576289f01b7126ece832346fd7f0cce06ae8243a3ea9f22636b97b014b50f0e

Contents?: true

Size: 583 Bytes

Versions: 6

Compression:

Stored size: 583 Bytes

Contents

require 'hashie'
require 'active_support/core_ext/string'

module PortalConnectors
  class SafeSettingsHash < Hash
    include Hashie::Extensions::IndifferentAccess
    include Hashie::Extensions::MethodAccess

    def [](key)
      fetch(key).tap do |value|
        raise(KeyError, "Key #{key} not assigned to non-blank value") if value.blank?
      end
    end

    def []=(key, value)
      if PortalConnectors.test_mode
        raise(KeyError, "Key #{key} not assigned outside of test_mode") unless has_key?(key)
      end

      indifferent_writer(key, value)
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
portal-connectors-0.58.39xc lib/portal-connectors/safe_settings_hash.rb
portal-connectors-0.58.39xb lib/portal-connectors/safe_settings_hash.rb
portal-connectors-0.58.39xa lib/portal-connectors/safe_settings_hash.rb
portal-connectors-0.58.39fj lib/portal-connectors/safe_settings_hash.rb
portal-connectors-0.58.39fg lib/portal-connectors/safe_settings_hash.rb
portal-connectors-0.58.38xn lib/portal-connectors/safe_settings_hash.rb