Forum: Ruby Rake as a library/API: possible?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
6bed507c0085d39447171b95c515a890?d=identicon&s=25 David Palm (Guest)
on 2009-05-13 13:12
(Received via mailing list)
Hi all,
I'm trying to use rake as a library/API to retrieve the rake tasks in a
given directory.

Basically I'm looking to mimic the output of
  rake --tasks --silent

Looking through the source code and trying out some stuff in irb I'm
getting the impression this usage was not considered at design stage.
But is it possible?

>> a = Rake::Application.new
=> #<Rake::Application:0x4e4c8...
>> a.init
...throws me out of IRB, as does "Rake::Application.new.run"

I've been trying for a good while to get around the above all to no
avail.

Can this be done? Am I better off by just doing:
  tasks = x%{rake --tasks --silent}

Thanks!
David
1389520a4eaa3d3e4523a76139e8f2e6?d=identicon&s=25 Ryan Davis (Guest)
on 2009-05-13 21:25
(Received via mailing list)
On May 13, 2009, at 04:11 , David Palm wrote:

> Looking through the source code and trying out some stuff in irb I'm
> getting the impression this usage was not considered at design
> stage. But is it possible?
>
>>> a = Rake::Application.new
> => #<Rake::Application:0x4e4c8...
>>> a.init
> ...throws me out of IRB, as does "Rake::Application.new.run"

I think the biggie is that Rake::Application is a singleton.

% ruby -rubygems -e 'require "rake"; load "Rakefile"; p
Rake.application.tasks.map { |t| t.name }.sort'
["announce", "audit", "autotest", "check_extra_deps",
"check_manifest", "clean", "clobber", "clobber_docs",
"clobber_package", "clobber_rcov", "config_hoe", "debug_gem",
"default", "deps:email", "deps:fetch", "deps:list", "doc", "doc/
index.html", "docs", "email", "flay", "flog", "gem", "generate_key",
"install_gem", "multi", "package", "pkg", "pkg/ZenTest-4.0.0", "pkg/
ZenTest-4.0.0.gem", "pkg/ZenTest-4.0.0.tgz", "post_blog", "post_news",
"publish_docs", "publish_on_announce", "rcov", "rcov_info",
"rcov_overlay", "redocs", "release", "repackage", "ridocs", "sort",
"test", "test_deps", "update"]
This topic is locked and can not be replied to.