Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6599749
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:31:52+00:00 2026-05-25T18:31:52+00:00

Is it possible to know the current rake task within ruby: # Rakefile task

  • 0

Is it possible to know the current rake task within ruby:

# Rakefile
task :install do
  MyApp.somemethod(options)
end

# myapp.rb
class MyApp
  def somemetod(opts)
     ## current_task?
  end
end

Edit

I’m asking about any enviroment|global variable that can be queried about that, because I wanted to make an app smart about rake, not modify the task itself. I’m thinking of making an app behave differently when it was run by rake.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T18:31:54+00:00Added an answer on May 25, 2026 at 6:31 pm

    I’m thinking of making an app behave different when runned by rake.

    Is it already enough to check caller, if it is called from rake, or do you need also which task?


    I hope, it is ok, when you can modify the rakefile. I have a version which introduce Rake.application.current_task.

    # Rakefile
    require 'rake'
    module Rake
      class Application
        attr_accessor :current_task
      end
      class Task
        alias :old_execute :execute 
        def execute(args=nil)
          Rake.application.current_task = @name  
          old_execute(args)
        end
      end #class Task
    end #module Rake  
    
    task :start => :install do; end
    task :install => :install2 do
      MyApp.new.some_method()
    end
    task :install2 do; end
    
    # myapp.rb
    class MyApp
      def some_method(opts={})
        ## current_task? -> Rake.application.current_task
        puts "#{self.class}##{__method__} called from task #{Rake.application.current_task}"
      end
    end
    

    Two remarks on it:

    • you may add the rake-modifications in a file and require it in your rakefile.
    • the tasks start and install are test tasks to test, if there are more then one task.
    • I made only small tests on side effects. I could imagine there are problems in a real productive situation.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know it is possible to set the current folder of the OpenFolderDialog to
Does any one know if its possible to animate app.current.mainwindow.width so that you get
Is it possible to know whether a Java class has been loaded, without attempting
I need to know if it is possible to obtain the current execution node?
Does anyone know if it is possible to access via code either from within
I would like to know whether the following are possible in the current windows
Is it possible to know the current quarter using Linux command line? I didn't
I'd like to know if it's possible to calculate the current moon phase or
I know that it is possible to fetch the lat-lng of the current location.
I don't know is it possible to do. I have two classes: public class

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.