Sha256: f4797b2b5f76073a3e12501904dbefd0504b2cc08bf8002c8b157eebf0786a53

Contents?: true

Size: 1.76 KB

Versions: 11

Compression:

Stored size: 1.76 KB

Contents

# frozen_string_literal: true

require 'eac_ruby_utils/core_ext'

module Avm
  module Instances
    module EntryKeys
      URI_FIELDS = %i[fragment hostname password path port query scheme url username].freeze

      class << self
        def all
          all_keys.to_a
        end

        def keys_consts_set(prefix, suffixes)
          if suffixes.is_a?(::Hash)
            keys_consts_set_from_hash(prefix, suffixes)
          elsif suffixes.is_a?(::Enumerable)
            keys_consts_set_from_enum(prefix, suffixes)
          else
            raise "Unmapped suffixes class: #{suffixes.class}"
          end
        end

        def key_const_set(prefix, suffix)
          key = [prefix, suffix].reject(&:blank?).join('.')
          const_set(key.gsub('.', '_').upcase, key)
          all_keys << key
        end

        private

        def all_keys
          @all_keys ||= ::Set.new
        end

        def keys_consts_set_from_enum(prefix, suffixes)
          suffixes.each { |suffix| key_const_set(prefix, suffix) }
        end

        def keys_consts_set_from_hash(prefix, suffixes)
          suffixes.each { |k, v| keys_consts_set(prefix.to_s + (k.blank? ? '' : ".#{k}"), v) }
        end
      end

      {
        '' => %w[data_fs_path fs_path name source_instance_id],
        admin: URI_FIELDS + %w[api_key],
        database: URI_FIELDS + %w[id limit name system timeout extra],
        docker: %w[registry],
        fs: %w[url],
        install: URI_FIELDS + %w[id groupname],
        mailer: {
          '' => %w[id from reply_to],
          smtp: URI_FIELDS + %w[address domain authentication openssl_verify_mode starttls_auto tls]
        },
        web: URI_FIELDS + %w[authority userinfo]
      }.each { |prefix, suffixes| keys_consts_set(prefix, suffixes) }
    end
  end
end

Version data entries

11 entries across 11 versions & 2 rubygems

Version Path
avm-0.37.0 lib/avm/instances/entry_keys.rb
eac_tools-0.24.0 sub/avm/lib/avm/instances/entry_keys.rb
avm-0.36.0 lib/avm/instances/entry_keys.rb
eac_tools-0.23.0 sub/avm/lib/avm/instances/entry_keys.rb
avm-0.35.1 lib/avm/instances/entry_keys.rb
eac_tools-0.22.0 sub/avm/lib/avm/instances/entry_keys.rb
eac_tools-0.21.0 sub/avm/lib/avm/instances/entry_keys.rb
eac_tools-0.20.0 sub/avm/lib/avm/instances/entry_keys.rb
eac_tools-0.19.0 sub/avm/lib/avm/instances/entry_keys.rb
avm-0.35.0 lib/avm/instances/entry_keys.rb
eac_tools-0.18.0 sub/avm/lib/avm/instances/entry_keys.rb