# Having problems fiddling with rake

**URL:** <https://www.ruby-forum.com/t/having-problems-fiddling-with-rake/88140>\
**Category:** Ruby\
**Created:** [March 8, 2007, 2:10pm UTC](https://www.ruby-forum.com/t/having-problems-fiddling-with-rake/88140 "2007-03-08T14:10:58Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![iceburgh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/c4cdca/32.png) [@iceburgh](https://www.ruby-forum.com/u/iceburgh)\
**Post date:** [March 8, 2007, 2:10pm UTC](https://www.ruby-forum.com/t/having-problems-fiddling-with-rake/88140/1 "2007-03-08T14:10:58Z")

</div>

I’m trying to get “rake doc:app” pull its input from a different  
Rails app’s source tree. In trying to prototype a solution, I’ve  
fiddled with documentation.rake. However, my hack isn’t working:

> rake aborted!  
> stack level too deep  
> /usr/local/lib/ruby/gems/1.8/gems/  
> rake-0.7.1/lib/rake.rb:1038:in `orig_include' rake-0.7.1/lib/rake.rb:1036:in `orig\_include’  
> rails-1.2.2/lib/tasks/documentation.rake:41:in `include’

My trace of the value being mapped contains only a series of:

new\_name=‘.//’

Any idea what I’m doing wrong? Here’s the relevant code:

# /usr/.local/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb defines

# the include method, as follows:

# 

# # Add file names defined by glob patterns to the file list.

# # If an array is given, add each element of the array.

# 

# # Example:

# # file\_list.include(“_.java", "_.cfg”)

# # file\_list.include %w( math.c lib.h \*.o )

# 

# def include(\*filenames)

# # TODO: check for pending

# filenames.each do |fn|

# if fn.respond\_to? :to\_ary

# include(\*fn.to\_ary)

# else

# @pending\_add \<\< fn

# end

# end

# @pending = true

# self

# end

# alias :add :include

# 

##### 

# 

# We can redefine this to add an arbitrary prefix to each path, based

# on the RDOC\_SRC\_DIR environment variable:

class FileList

```
@@rdoc_src_dir = ENV['RDOC_SRC_DIR']

if (@@rdoc_src_dir)
  alias :orig_include :include

  def include(*filenames)
    list = filenames.map do |name|
      new_name = "#{@@rdoc_src_dir}/#{name}"
      puts "new_name='#{new_name}'" #T
    end
    orig_include(list)
  end
  alias :add :include
end

```

end  
…

More generally, if someone has a better way to solve the original  
problem, I’d be happy to hear about it!

## -r

[http://www.cfcl.com/rdm](http://www.cfcl.com/rdm) Rich M.  
[http://www.cfcl.com/rdm/resume](http://www.cfcl.com/rdm/resume) removed\_email\_address@domain.invalid  
[http://www.cfcl.com/rdm/weblog](http://www.cfcl.com/rdm/weblog) +1 650-873-7841

Technical editing and writing, programming, and web development

---

<div class="post-metadata">

**Author:** ![iceburgh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/c4cdca/32.png) [@iceburgh](https://www.ruby-forum.com/u/iceburgh)\
**Post date:** [March 8, 2007, 8:27pm UTC](https://www.ruby-forum.com/t/having-problems-fiddling-with-rake/88140/2 "2007-03-08T20:27:32Z")

</div>

Rich M. wrote:

> Any idea what I’m doing wrong? Here’s the relevant code:  
> class FileList
> 
> ```
> @@rdoc_src_dir = ENV['RDOC_SRC_DIR']
> 
> if (@@rdoc_src_dir)
> alias :orig_include :include
> 
> def include(*filenames)
> list = filenames.map do |name|
> new_name = "#{@@rdoc_src_dir}/#{name}"
> puts "new_name='#{new_name}'" #T
> 
> ```

```
        ^^^^

```

> ```
> end
> orig_include(list)
> end
> alias :add :include
> end
> 
> ```
> 
> end  
> …

Puts doesn’t return a useful value for +map+ to use.

That being said, I don’t see why you don’t just duplicate the rails  
doc:app task and replace the filelists with what you need. It is  
probably less code than what you’ve invested in hacking FileList#include  
and it will be much less error prone.

– Jim W.

---

<div class="post-metadata">

**Author:** ![iceburgh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/c4cdca/32.png) [@iceburgh](https://www.ruby-forum.com/u/iceburgh)\
**Post date:** [March 8, 2007, 8:38pm UTC](https://www.ruby-forum.com/t/having-problems-fiddling-with-rake/88140/3 "2007-03-08T20:38:55Z")

</div>

At 4:27 AM +0900 3/9/07, Jim W. wrote:

> Puts doesn’t return a useful value for +map+ to use.

Point taken, but it didn’t work even without the puts. So,  
my Ruby question remains…

> That being said, I don’t see why you don’t just duplicate  
> the rails doc:app task and replace the filelists with  
> what you need. It is probably less code than what you’ve  
> invested in hacking FileList#include and it will be much  
> less error prone.

I have considered that and may end up doing so, but it would  
mean tracking the changes to the original task, which is the  
kind of maintenance sinkhole I try to avoid.

## -r

[http://www.cfcl.com/rdm](http://www.cfcl.com/rdm) Rich M.  
[http://www.cfcl.com/rdm/resume](http://www.cfcl.com/rdm/resume) removed\_email\_address@domain.invalid  
[http://www.cfcl.com/rdm/weblog](http://www.cfcl.com/rdm/weblog) +1 650-873-7841

Technical editing and writing, programming, and web development

---

<div class="post-metadata">

**Author:** ![iceburgh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/c4cdca/32.png) [@iceburgh](https://www.ruby-forum.com/u/iceburgh)\
**Post date:** [March 8, 2007, 9:16pm UTC](https://www.ruby-forum.com/t/having-problems-fiddling-with-rake/88140/4 "2007-03-08T21:16:59Z")

</div>

At 4:48 AM +0900 3/9/07, Jim W. wrote:

> The original task uses a rake standard RDocTask. Of  
> the six lines that configure it, three consist of  
> selecting the right files (which is the part you want  
> to change) and the other three set the document  
> directory, the title and a few options.
> 
> Doesn’t seem to be too onerous.

The onerous part is keeping track of the library, in  
order to look at the file and see if I NEED to make the  
changes. I’m also I’m a bit mystified as to how I’d  
(cleanly) change the standard task to get the effect I  
want. I’ll try explaining again; perhaps you can help.

I want to be able to have one Rails app generate doc/…  
files, based on the file tree of another app. That is,  
the results should appear locally, but the sources should  
stay (unmodified) over in the other app.

I don’t see six lines (in documentation.rake). Rather, I  
see a long laundry list of “rdoc.rdoc\_files.include” calls,  
relative to the current directory. The output files (and  
actions such as rm\_rf) are also defined in terms of the  
current directory.

So, doing a chdir won’t help. I could edit the file to  
change the laundry lists, but that seemed onerous to me.  
So, I started looking at redefining “include”. How would  
you approach this problem, specifically?

-r

## P.S. Still having problems with my include aliasing…

[http://www.cfcl.com/rdm](http://www.cfcl.com/rdm) Rich M.  
[http://www.cfcl.com/rdm/resume](http://www.cfcl.com/rdm/resume) removed\_email\_address@domain.invalid  
[http://www.cfcl.com/rdm/weblog](http://www.cfcl.com/rdm/weblog) +1 650-873-7841

Technical editing and writing, programming, and web development

---

<div class="post-metadata">

**Author:** ![iceburgh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/c4cdca/32.png) [@iceburgh](https://www.ruby-forum.com/u/iceburgh)\
**Post date:** [March 8, 2007, 10:24pm UTC](https://www.ruby-forum.com/t/having-problems-fiddling-with-rake/88140/5 "2007-03-08T22:24:17Z")

</div>

FYI, my current (working) solution looks like this:

namespace :doc do

# On occasion, we want to grovel over another app’s file tree, but

# put the results in our own DOC directory. In order to make this

# happen, we do the following:

# 

# % setenv README\_FOR\_APP …

# Make sure that $RDOC\_SRC\_DIR/doc/README\_FOR\_APP exists.

# In the following code, do some chdir magic.

## rdoc\_src\_dir = ENV[‘RDOC\_SRC\_DIR’] if (rdoc\_src\_dir) save\_wd = getwd chdir(rdoc\_src\_dir) else save\_wd = ‘.’ end … rdoc.rdoc\_dir = “#{save\_wd}/doc/api” …

[http://www.cfcl.com/rdm](http://www.cfcl.com/rdm) Rich M.  
[http://www.cfcl.com/rdm/resume](http://www.cfcl.com/rdm/resume) removed\_email\_address@domain.invalid  
[http://www.cfcl.com/rdm/weblog](http://www.cfcl.com/rdm/weblog) +1 650-873-7841

Technical editing and writing, programming, and web development

---

<div class="post-metadata">

**Author:** ![iceburgh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/c4cdca/32.png) [@iceburgh](https://www.ruby-forum.com/u/iceburgh)\
**Post date:** [March 8, 2007, 8:48pm UTC](https://www.ruby-forum.com/t/having-problems-fiddling-with-rake/88140/6 "2007-03-08T20:48:27Z")

</div>

Rich M. wrote:

> I have considered that and may end up doing so, but it would  
> mean tracking the changes to the original task, which is the  
> kind of maintenance sinkhole I try to avoid.

The original task uses a rake standard RDocTask. Of the six lines that  
configure it, three consist of selecting the right files (which is the  
part you want to change) and the other three set the document directory,  
the title and a few options.

Doesn’t seem to be too onerous.

Now, duplicating the “doc:rails” task would be another issue.

– Jim W.
