class ElasticAPM::Config

@api private
rubocop:disable Metrics/ClassLength

def app=(app)

def app=(app)
  case app_type?(app)
  when :sinatra
    set_sinatra(app)
  when :rails
    set_rails(app)
  else
    self.service_name = 'ruby'
  end
end

def app_type?(app)

def app_type?(app)
  if defined?(::Rails::Application) && app.is_a?(::Rails::Application)
    return :rails
  end
  if app.is_a?(Class) && app.superclass.to_s == 'Sinatra::Base'
    return :sinatra
  end
  nil
end

def assign(update)

def assign(update)
  return unless update
  update.each { |key, value| send(:"#{key}=", value) }
end

def available_spies

rubocop:disable Metrics/MethodLength
def available_spies
  %w[
    delayed_job
    elasticsearch
    faraday
    http
    json
    mongo
    net_http
    redis
    sequel
    sidekiq
    sinatra
    tilt
    rake
  ]
end

def build_logger

def build_logger
  Logger.new(log_path == '-' ? STDOUT : log_path).tap do |logger|
    logger.level = log_level
  end
end

def capture_body=(value)

rubocop:disable Metrics/MethodLength
def capture_body=(value)
  if value =~ /(all|transactions|errors|off)/
    set(:capture_body, value)
    return
  end
  case value
  when true
    warn "Boolean value for option `capture_body' has " \
      "been deprecated. Setting to 'all'"
    self.capture_body = 'all'
  when false
    warn "Boolean value for option `capture_body' has " \
      "been deprecated. Setting to 'off'"
    self.capture_body = 'off'
  else
    default = options[:capture_body].default
    warn "Unknown value `#{value}' for option "\
      "`capture_body'. Defaulting to `#{default}'"
    self.capture_body = default
  end
end

def collect_metrics?

def collect_metrics?
  metrics_interval > 0
end

def enabled_spies

def enabled_spies
  available_spies - disabled_spies
end

def format_name(str)

def format_name(str)
  str && str.gsub('::', '_')
end

def initialize(options = {})

rubocop:disable Metrics/MethodLength
def initialize(options = {})
  @options = load_schema
  custom_logger = options.delete(:logger)
  assign(options)
  # Pick out config_file specifically as we need it now to load it,
  # but still need the other env vars to have precedence
  env = load_env
  if (env_config_file = env.delete(:config_file))
    self.config_file = env_config_file
  end
  assign(load_config_file)
  assign(env)
  yield self if block_given?
  @logger = custom_logger || build_logger
  @__view_paths = []
  @__root_path = Dir.pwd
end

def inspect

def inspect
  super.split.first + '>'
end

def load_config_file

def load_config_file
  return unless File.exist?(config_file)
  read = File.read(config_file)
  evaled = ERB.new(read).result
  YAML.safe_load(evaled)
end

def load_env

def load_env
  @options.values.each_with_object({}) do |option, opts|
    next unless (value = ENV[option.env_key])
    opts[option.key] = value
  end
end

def method_missing(name, *args)

def method_missing(name, *args)
  return super unless DEPRECATED_OPTIONS.include?(name)
  warn "The option `#{name}' has been removed."
end

def rails_app_name(app)

def rails_app_name(app)
  if ::Rails::VERSION::MAJOR >= 6
    app.class.module_parent_name
  else
    app.class.parent_name
  end
end

def set_rails(app) # rubocop:disable Metrics/AbcSize

rubocop:disable Metrics/AbcSize
def set_rails(app) # rubocop:disable Metrics/AbcSize
  self.service_name ||= format_name(service_name || rails_app_name(app))
  self.framework_name ||= 'Ruby on Rails'
  self.framework_version ||= ::Rails::VERSION::STRING
  self.logger ||= ::Rails.logger
  self.__root_path = ::Rails.root.to_s
  self.__view_paths = app.config.paths['app/views'].existent
end

def set_sinatra(app)

def set_sinatra(app)
  self.service_name = format_name(service_name || app.to_s)
  self.framework_name = framework_name || 'Sinatra'
  self.framework_version = framework_version || Sinatra::VERSION
  self.__root_path = Dir.pwd
end

def span_frames_min_duration=(value)

def span_frames_min_duration=(value)
  super
  @span_frames_min_duration_us = nil
end

def span_frames_min_duration?

def span_frames_min_duration?
  span_frames_min_duration != 0
end

def span_frames_min_duration_us

def span_frames_min_duration_us
  @span_frames_min_duration_us ||= span_frames_min_duration * 1_000_000
end

def use_ssl?

def use_ssl?
  server_url.start_with?('https')
end