Sha256: aca9029445c7165074262d3cd20e93457b1934b242eb69450038417b19a5de9c

Contents?: true

Size: 1021 Bytes

Versions: 20

Compression:

Stored size: 1021 Bytes

Contents

# frozen_string_literal: true

require 'delegate'

module AppStoreConnect
  class Client
    class Options < SimpleDelegator
      attr_reader :kwargs, :config, :env

      DEFAULTS = {
        analytics_enabled: true,
        schema: Schema.new(File.join(__dir__, '..', '..', 'config', 'schema.json'))
      }.freeze
      private_constant :DEFAULTS

      ENV_REGEXP = /APP_STORE_CONNECT_(?<suffix>[A-Z_]+)/.freeze
      private_constant :ENV_REGEXP

      def initialize(kwargs = {})
        @kwargs = kwargs
        @config = build_config
        @env = build_env

        options = DEFAULTS.merge(@env.merge(@config.merge(kwargs)))

        super(options)
      end

      private

      def build_config
        AppStoreConnect.config.dup
      end

      def build_env
        {}.tap do |hash|
          ENV.each do |key, value|
            match = key.match(ENV_REGEXP)

            next unless match

            hash[match[:suffix].downcase.to_sym] = value
          end
        end
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
app_store_connect-0.38.0 lib/app_store_connect/client/options.rb
app_store_connect-0.37.0 lib/app_store_connect/client/options.rb
app_store_connect-0.36.0 lib/app_store_connect/client/options.rb
app_store_connect-0.35.0 lib/app_store_connect/client/options.rb
app_store_connect-0.34.0 lib/app_store_connect/client/options.rb
app_store_connect-0.33.0 lib/app_store_connect/client/options.rb
app_store_connect-0.32.0 lib/app_store_connect/client/options.rb
app_store_connect-0.30.0 lib/app_store_connect/client/options.rb
app_store_connect-0.29.0 lib/app_store_connect/client/options.rb
app_store_connect-0.28.0 lib/app_store_connect/client/options.rb
app_store_connect-0.27.0 lib/app_store_connect/client/options.rb
app_store_connect-0.26.0 lib/app_store_connect/client/options.rb
app_store_connect-0.25.0 lib/app_store_connect/client/options.rb
app_store_connect-0.23.0 lib/app_store_connect/client/options.rb
app_store_connect-0.22.0 lib/app_store_connect/client/options.rb
app_store_connect-0.21.0 lib/app_store_connect/client/options.rb
app_store_connect-0.20.0 lib/app_store_connect/client/options.rb
app_store_connect-0.19.0 lib/app_store_connect/client/options.rb
app_store_connect-0.18.0 lib/app_store_connect/client/options.rb
app_store_connect-0.17.0 lib/app_store_connect/client/options.rb