Sha256: a2958cfdd947e49fb3f38be0fabe0aeb33f427ad768ec8ad25e38a08747fbf26

Contents?: true

Size: 1.16 KB

Versions: 39

Compression:

Stored size: 1.16 KB

Contents

# frozen_string_literal: true

require "yaml"
require "active_support/encrypted_file"
require "active_support/ordered_options"
require "active_support/core_ext/object/inclusion"
require "active_support/core_ext/module/delegation"

module ActiveSupport
  class EncryptedConfiguration < EncryptedFile
    delegate :[], :fetch, to: :config
    delegate_missing_to :options

    def initialize(config_path:, key_path:, env_key:, raise_if_missing_key:)
      super content_path: config_path, key_path: key_path,
        env_key: env_key, raise_if_missing_key: raise_if_missing_key
    end

    # Allow a config to be started without a file present
    def read
      super
    rescue ActiveSupport::EncryptedFile::MissingContentError
      ""
    end

    def write(contents)
      deserialize(contents)

      super
    end

    def config
      @config ||= deserialize(read).deep_symbolize_keys
    end

    private
      def options
        @options ||= ActiveSupport::InheritableOptions.new(config)
      end

      def serialize(config)
        config.present? ? YAML.dump(config) : ""
      end

      def deserialize(config)
        YAML.load(config).presence || {}
      end
  end
end

Version data entries

39 entries across 39 versions & 6 rubygems

Version Path
activesupport-5.2.8.1 lib/active_support/encrypted_configuration.rb
activesupport-5.2.8 lib/active_support/encrypted_configuration.rb
activesupport-5.2.7.1 lib/active_support/encrypted_configuration.rb
activesupport-5.2.7 lib/active_support/encrypted_configuration.rb
activesupport-5.2.6.3 lib/active_support/encrypted_configuration.rb
activesupport-5.2.6.2 lib/active_support/encrypted_configuration.rb
activesupport-5.2.6.1 lib/active_support/encrypted_configuration.rb
activesupport-5.2.6 lib/active_support/encrypted_configuration.rb
activesupport-5.2.4.6 lib/active_support/encrypted_configuration.rb
activesupport-5.2.5 lib/active_support/encrypted_configuration.rb
activesupport-5.2.4.5 lib/active_support/encrypted_configuration.rb
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.4.1/lib/active_support/encrypted_configuration.rb
activesupport-5.2.4.4 lib/active_support/encrypted_configuration.rb
activesupport-5.2.4.3 lib/active_support/encrypted_configuration.rb
activesupport-5.2.4.2 lib/active_support/encrypted_configuration.rb
grape-extra_validators-1.0.0 vendor/bundle/ruby/2.4.0/gems/activesupport-5.2.4.1/lib/active_support/encrypted_configuration.rb
activesupport-5.2.4.1 lib/active_support/encrypted_configuration.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/activesupport-5.2.3/lib/active_support/encrypted_configuration.rb
activesupport-5.2.4 lib/active_support/encrypted_configuration.rb
activesupport-5.2.4.rc1 lib/active_support/encrypted_configuration.rb