Module: Dapp::Dapp::DappConfig

Included in:
Dapp::Dapp
Defined in:
lib/dapp/dapp/dapp_config.rb

Constant Summary collapse

SUPPORTED_CONFIG_OPTIONS =
{
  verbose:   [FalseClass, TrueClass],
  quiet:     [FalseClass, TrueClass],
  dev:       [FalseClass, TrueClass],
  time:      [FalseClass, TrueClass],
  dry_run:   [FalseClass, TrueClass],
  build_dir: [String],
  color:     [String]
}

Instance Method Summary collapse

Instance Method Details

#config_optionsObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/dapp/dapp/dapp_config.rb', line 36

def config_options
  @config_options ||= begin
    config_search_paths = []
    config_search_paths << File.join(Dir.home)
    config_search_paths << path if dappfile_exists?

    config_search_paths.reduce({}) do |options, dir|
      if (config_options_path = make_path(dir, '.dapp_config')).file?
        config_options = begin
          yaml_load_file(config_options_path).tap do |c_options|
            c_options.merge!(c_options.in_depth_merge(c_options['ci'] || {})) if ENV['GITLAB_CI'] || ENV['TRAVIS']
            c_options.delete('ci')
          end
        rescue Psych::SyntaxError => e
          raise Error::Dapp, code: :dapp_config_file_incorrect, data: { message: e.message }
        end
        options.in_depth_merge(config_options)
      else
        options
      end
    end.symbolize_keys
  end
end

#option_colorObject



20
21
22
23
24
25
26
# File 'lib/dapp/dapp/dapp_config.rb', line 20

def option_color
  if options[:color] == 'auto'
    config_options[:color] || 'auto'
  else
    options[:color]
  end
end

#option_devObject



28
29
30
31
32
33
34
# File 'lib/dapp/dapp/dapp_config.rb', line 28

def option_dev
  if options[:dev].nil?
    config._dev_mode || config_options[:dev]
  else
    options[:dev]
  end
end

#validate_config_options!Object



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/dapp/dapp/dapp_config.rb', line 60

def validate_config_options!
  data_list_format = proc { |list| list.map { |e| "'#{e}'" }.join(', ') }

  unless (unsupported_keys = config_options.select { |k, _| !SUPPORTED_CONFIG_OPTIONS.keys.include?(k) }.keys).empty?
    log_warning(desc: { code: :unsupported_dapp_config_options,
                        data: { options: data_list_format.call(unsupported_keys),
                                supported_options: data_list_format.call(SUPPORTED_CONFIG_OPTIONS.keys) } })
  end

  config_options.each do |k, v|
    next unless SUPPORTED_CONFIG_OPTIONS.keys.include?(k)

    if k == :color
      raise Error::Dapp,
            code: :incorrect_dapp_config_option_color,
            data: { value: v, expected: data_list_format.call(%w(auto on off)) } unless %w(auto on off).member?(v)
    elsif !SUPPORTED_CONFIG_OPTIONS[k].member? v.class
      raise Error::Dapp,
            code: :incorrect_dapp_config_option,
            data: { option: k, value: v, expected: data_list_format.call(SUPPORTED_CONFIG_OPTIONS[k]) }
    end
  end
end