buildr-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Antoine Toulme <anto...@lunar-ocean.com>
Subject Re: Correct Use of the 'tap' Method
Date Thu, 23 May 2013 15:23:24 GMT
This is more of a Rake question actually. Rake provides ways for you to
define tasks.
So when you type task(:compile) do |task| ... you are actually redefining
the compile task. That's why it's doing nothing.

Rake provides a way to define task dependencies as tasks. Buildr builds on
this by adding the tap method which lets you add a dependent task directly
on the compile task. tap inserts the dependency as the first item in the
list, so if you tap twice, the second time will execute before the first
time.

I hope this helps.


On Thu, May 23, 2013 at 6:11 AM, Adam George <atg103@googlemail.com> wrote:

> Hi,
>
> I'm relatively new to Buildr/Ruby and whilst I'm getting the hang of most
> things there is still one thing that I don't understand.
>
> Consider this:
>
>         # example 1 (seems to do nothing)
>         task(:compile) do |task|
>                 task.sources = [path_to(:source, :main, :catalina)]
>                 task.with "org.apache.tomcat:tomcat-catalina:jar:7.0.35",
>                         "javax.servlet:servlet-api:jar:2.5"
>                 task.into(_(:target, :classes, :catalina))
>         end
>
> ... and this:
>
>         # example 2 (works as expected)
>         task(:compile).tap do |task|
>                 task.sources = [path_to(:source, :main, :catalina)]
>                 task.with "org.apache.tomcat:tomcat-catalina:jar:7.0.35",
>                         "javax.servlet:servlet-api:jar:2.5"
>                 task.into(_(:target, :classes, :catalina))
>         end
>
> Both code blocks receive a task argument that identifies itself as
> "my_project:compile" when printed to the console, but I can't understand
> why
> the enhancement in example 1 does nothing to the compile task of
> my_project.
>
> I'm comfortable with the fact that I need to use .tap, but I don't really
> understand why it's necessary. If both functions are given the same
> argument
> at run time, why does only the second example work?  What is happening in
> example 1 in this case?
>
> Thanks and regards,
>
> Adam George
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message