buildr-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Peter Donald <pe...@realityforge.org>
Subject Re: Layouts customized by project attributes
Date Sat, 20 Mar 2010 01:49:42 GMT
On Sat, Mar 20, 2010 at 11:14 AM, Antoine Toulme
<antoine@lunar-ocean.com> wrote:
> Ruby can use instance_eval to do this.
>
> Use instance_eval inside a method to which you pass arguments to define
> projects dynamically.

Ok. I don't understand what you are suggesting. What I am trying to do
is have the layout customize itself based on the project to which it
is assigned. To do this the layout object needs to have access to the
project or the project needs to be able to decorate the layout when it
is assigned.

It may be simpler to describe it in a patch (that is untested and
really just to illustrate an idea)

diff --git a/lib/buildr/core/project.rb b/lib/buildr/core/project.rb
index 2cde99b..fd1a053 100644
--- a/lib/buildr/core/project.rb
+++ b/lib/buildr/core/project.rb
@@ -439,7 +439,8 @@ module Buildr

     # Returns the layout associated with this project.
     def layout
-      @layout ||= (parent ? parent.layout : Layout.default).clone
+      self.layout = (parent ? parent.layout : Layout.default).clone
unless @layout
+      @layout
     end

     # :call-seq:
@@ -621,6 +622,9 @@ module Buildr
     def layout=(layout)
       raise 'Cannot set directory layout twice, or after reading its
value' if @layout
       @layout = layout.is_a?(Class) ? layout.new : layout
+      assign_method = "project=".to_sym
+      @layout.send(assign_method, self) if @layout.respond_to? assign_method
+      @layout
     end

     # :call-seq:

-- 
Cheers,

Peter Donald

Mime
View raw message