# frozen_string_literal: true

# Local path overrides for development.
# Loaded by the associated non-local gemfile when KETTLE_DEV_DEV != "false".

# Bootstrapping nomono here cannot rely on a plain `gem "nomono", ...` line.
# Bundler records that dependency during Gemfile evaluation, but it does not
# activate that exact version before the immediate `require "nomono/bundler"`.
nomono_activation_requirements = ["~> 1.1", ">= 1.1.1"]
nomono_lockfile = File.expand_path("../../Gemfile.lock", __dir__)
if File.file?(nomono_lockfile)
  require "bundler"
  nomono_locked_spec = Bundler::LockfileParser
    .new(Bundler.read_file(nomono_lockfile))
    .specs
    .find { |spec| spec.name == "nomono" }
  nomono_locked = nomono_locked_spec &&
    Gem::Requirement.new(nomono_activation_requirements).satisfied_by?(nomono_locked_spec.version)
  nomono_activation_requirements = ["= #{nomono_locked_spec.version}"] if nomono_locked
end
Kernel.send(:gem, "nomono", *nomono_activation_requirements)
require "nomono/bundler"

local_gems = ["kettle-dev", "kettle-family", "kettle-test", "kettle-soup-cover", "kettle-drift"]
declared_gems = instance_variable_get(:@dependencies).to_a.map(&:name)
local_gems_to_eval = local_gems - ["rspec-stubbed_env"] - declared_gems

# export KETTLE_DEV_DEV=/path/to/my
platform :mri do
  eval_nomono_gems(
    :gems => local_gems_to_eval,
    :prefix => "KETTLE_DEV",
    :path_env => "KETTLE_DEV_DEV",
    :vendored_gems_env => "VENDORED_GEMS",
    :vendor_gem_dir_env => "VENDOR_GEM_DIR",
    :debug_env => "KETTLE_DEV_DEBUG",
    :root => ["src", "my", "kettle-dev"]
  )

  if ENV.fetch("GALTZO_FLOSS_DEV", "false").casecmp("false") != 0
    eval_nomono_gems(
      :gems => ["turbo_tests2"],
      :prefix => "GALTZO_FLOSS",
      :path_env => "GALTZO_FLOSS_DEV",
      :vendored_gems_env => "GALTZO_FLOSS_VENDORED_GEMS",
      :vendor_gem_dir_env => "GALTZO_FLOSS_VENDOR_GEM_DIR",
      :debug_env => "GALTZO_FLOSS_DEBUG"
    )
  end
end
