Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get the current namespace in Rake?

Tags:

ruby

rake

namespace :baseline do
  INDEX_DIR = index(:baseline) # context
  task(:foo) ...
end

How do I get the :baseline Symbol in this context?

like image 464
Reactormonk Avatar asked Dec 06 '11 12:12

Reactormonk


People also ask

How do I add additional rake files to my project?

Additional rake files (with the file extension “ .rake ”) may be placed in rakelib directory located at the top level of a project (i.e. the same directory that contains the main Rakefile ). Also, rails projects may include additional rake files in the lib/tasks directory. Through require 'rake/clean' Rake provides clean and clobber tasks:

Where are rake tasks run from?

As far as rake is concerned, all tasks are run from the directory in which the Rakefile resides. Not all tasks need to be included in a single Rakefile.

Can I have a task with the same name as namespace?

You can define a task with the same name as your namespace. It is not as pretty as having the default task defined inside the namespace itself I think. desc "runs bar & baz in foo" task foo: ["foo:bar", "foo:baz"] namespace :foo do desc "bar in foo" task :bar do puts "bar" end desc "baz in foo" task :baz do puts "baz" end end

How does the import command work in Rake?

The import command addresses this by specifying a file to be loaded after the main rakefile is loaded, but before any targets on the command line are invoked. In addition, if the file name matches an explicit task, that task is invoked before loading the file.


1 Answers

namespace :baseline do |namespace|
  scope = namespace.instance_variable_get("@scope")

  INDEX_DIR = index(scope)

  task(:foo) ...
end
like image 53
Nerian Avatar answered Oct 16 '22 12:10

Nerian