Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

How to determine whether any prerequisite tasks needed to run at the time they were defined?

Aperta
#270 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
42/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
ruby
Ambito
build-system

Direzione di ricerca

Inizia dai punti di ingresso di Rake::Task mostrati nell’issue: #needed?, #already_invoked, #execute, #enhance e invoke_prerequisites. Traccia quando cambia ciascuno stato e determina come distinguere un prerequisito che è stato effettivamente eseguito da uno che è stato solo invocato. Il lavoro è completato quando il comportamento è specificato e coperto da test per entrambi i casi.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

I have a use-case in which I need to run a task if and only if at least one of its prerequisite tasks either (1) currently needs to run or (2) needed to run at the time the prerequisite task was defined. Here are some attempts at a Rake::Task subclass:

class MyTask < Rake::Task
  def needed?
    prerequisite_tasks.any?(&:needed?)
  end
end

This approach does not work, since at the time MyTask#needed? is called, prerequisite tasks may have run and therefore return false for #needed?.

class MyTask < Rake::Task
  def needed?
    prerequisite_tasks.any? { |p| p.needed? or p.already_invoked }
  end
end

This also doesn't work, since #already_invoked can return true [even if the task's #execute method was never called]:

          @already_invoked = true


          invoke_prerequisites(task_args, new_chain)
          execute(task_args) if needed?

What ended up working was:

class MyTask < Rake::Task
  def initialize(*)
    @needed = false
    super
  end
  
  def enhance(*)
    super.tap { @needed |= prerequisite_tasks.any?(&:needed?) }
  end

  def needed?
    @needed
  end
end

But that just feels... wrong. Is there something I'm missing here? I'd be more than happy to open a PR implementing what I'm looking for (maybe an #already_executed method?) if this functionality doesn't already exist.

Thanks!

Lingua principale
Ruby
Stelle
2.5k
Fork
650
Merge medio
6m
PR unite (30g)
3

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di ruby/rake

Tutte le issue di ruby/rake

Issue simili

Altre issue su Ruby

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.