class GemHadar

def yard_doc_task

def yard_doc_task
  YARD::Rake::YardocTask.new(:yard_doc) do |t|
    t.files = files.select { _1 =~ /\.rb\z/ }
    output_dir = yard_dir
    t.options = [ "--output-dir=#{output_dir}" ]
    # Include private & protected methods in documentation
    t.options << '--private' << '--protected'
    # Handle readme if present
    if readme && File.exist?(readme)
      t.options << "--readme=#{readme}"
    end
    # Add additional documentation files
    if doc_files&.any?
      t.files.concat(doc_files.flatten)
    end
    # Add before hook for cleaning
    t.before = proc {
      clean output_dir
      puts "Generating full documentation in #{output_dir}..."
    }
  end
end