Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

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

Đang mở
#270 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
42/100
Loại issue
Tính năng
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
ruby
Lĩnh vực
build-system

Hướng nghiên cứu

Bắt đầu với các điểm vào của Rake::Task được nêu trong issue: #needed?, #already_invoked, #execute, #enhance và invoke_prerequisites. Theo dõi thời điểm từng trạng thái thay đổi và xác định cách phân biệt một prerequisite thực sự đã được thực thi với một prerequisite chỉ được gọi. Được xem là hoàn tất khi hành vi đã được đặc tả và được kiểm thử cho cả hai trường hợp.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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!

Ngôn ngữ chính
Ruby
Star
2.5k
Fork
650
Merge trung bình
6 phút
Pull request đã merge (30 ngày)
3

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của ruby/rake

Tất cả issue của ruby/rake

Issue tương tự

Thêm issue về Ruby

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.