version_file = File.expand_path('.rails-version', __dir__)
RAILS_VERSION = ENV['RAILS_VERSION'] || (File.exist?(version_file) && File.read(version_file).chomp) || ""

MAJOR =
  case RAILS_VERSION
  when /5-2-stable/
    5
  when /master/, /stable/, nil, false, ''
    6
  else
    /(\d+)[\.|-]\d+/.match(RAILS_VERSION).captures.first.to_i
  end

if MAJOR >= 6
# sqlite3 is an optional, unspecified, dependency and Rails 6.0 only supports `~> 1.4`
  gem 'sqlite3', '~> 1.4', platforms: [:ruby]
else
# Similarly, Rails 5.0 only supports '~> 1.3.6'. Rails 5.1-5.2 support '~> 1.3', '>= 1.3.6'
  gem 'sqlite3', '~> 1.3.6', platforms: [:ruby]
end
