Method: AppMap::Config.load

Defined in:
lib/appmap/config.rb

.load(config_data) ⇒ Object

Loads configuration from a Hash.



391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
# File 'lib/appmap/config.rb', line 391

def load(config_data)
  name = config_data["name"] || Service::Guesser.guess_name
  config_params = {
    exclude: config_data["exclude"]
  }.compact

  if config_data["functions"]
    config_params[:functions] = config_data["functions"].map do |hook_decl|
      if hook_decl["name"] || hook_decl["package"]
        declare_hook_deprecated(hook_decl)
      else
        # Support the same syntax within the 'functions' that's used for externalized
        # hook config.
        declare_hook(hook_decl)
      end
    end.flatten
  end

  config_params[:packages] = \
    if config_data["packages"]
      config_data["packages"].map do |package|
        gem = package["gem"]
        path = package["path"]
        raise "AppMap config 'package' element should specify 'gem' or 'path', not both" if gem && path
        raise "AppMap config 'package' element should specify 'gem' or 'path'" unless gem || path

        if gem
          shallow = package["shallow"]
          # shallow is true by default for gems
          shallow = true if shallow.nil?

          require_name = \
            package["package"] || # deprecated
            package["require_name"]
          Package.build_from_gem(gem, require_name: require_name, exclude: package["exclude"] || [], shallow: shallow)
        else
          Package.build_from_path(path, exclude: package["exclude"] || [], shallow: package["shallow"])
        end
      end.compact
    else
      Array(Service::Guesser.guess_paths).map do |path|
        Package.build_from_path(path)
      end
    end

  if config_data["swagger"]
    swagger_config = Swagger::Configuration.load(config_data["swagger"])
    config_params[:swagger_config] = swagger_config
  end
  if config_data["depends"]
    depends_config = Depends::Configuration.load(config_data["depends"])
    config_params[:depends_config] = depends_config
  end

  Config.new name, **config_params
end