module Gem

def self.freebsd_platform?

def self.freebsd_platform?
  RbConfig::CONFIG["host_os"].to_s.include?("bsd")
end

def URI(uri) # rubocop:disable Naming/MethodName

rubocop:disable Naming/MethodName
def URI(uri) # rubocop:disable Naming/MethodName
  Bundler::URI(uri)
end

def match_gem?(platform, gem_name)

def match_gem?(platform, gem_name)
  match_platforms?(platform, Gem.platforms)
end

def match_platforms?(platform, platforms)

def match_platforms?(platform, platforms)
  platforms.any? do |local_platform|
    platform.nil? ||
      local_platform == platform ||
      (local_platform != Gem::Platform::RUBY && platform =~ local_platform)
  end
end

def match_spec?(spec)

def match_spec?(spec)
  match_gem?(spec.platform, spec.name)
end

def open_file_with_flock(path, &block)

def open_file_with_flock(path, &block)
  # read-write mode is used rather than read-only in order to support NFS
  mode = IO::RDWR | IO::APPEND | IO::CREAT | IO::BINARY
  mode |= IO::SHARE_DELETE if IO.const_defined?(:SHARE_DELETE)
  File.open(path, mode) do |io|
    begin
      io.flock(File::LOCK_EX)
    rescue Errno::ENOSYS, Errno::ENOTSUP
    end
    yield io
  end
end

def open_file_with_lock(path, &block)

def open_file_with_lock(path, &block)
  file_lock = "#{path}.lock"
  open_file_with_flock(file_lock, &block)
ensure
  FileUtils.rm_f file_lock
end