File: options.rb

package info (click to toggle)
ruby-app-store-connect 0.37.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 444 kB
  • sloc: ruby: 856; makefile: 4
file content (48 lines) | stat: -rw-r--r-- 1,021 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# 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