class Buildr::Layout

Symbolic mapping for directory layout. Used for both the default and custom layouts.

For example, the default layout maps [:source, :main, :java] to 'src/main/java', and

:target, :main, :classes

to 'target/classes'. You can use this to change the layout

of your projects.

To map [:source, :main] into the 'sources' directory:

my_layout = Layout.new
my_layout[:source, :main] = 'sources'

define 'foo', :layout=>my_layout do
  ...
end

To map [:source, :main, :java] to 'java/main':

class MainLast < Layout
  def expand(*args)
    if args[0..1] == [:source, :main]
      super args[2], :main, *args[3,]
    else
      super
    end
  end
end

define 'foo', :layout=>MainLast do
  ...
end

Attributes

default[RW]

Default layout used by new projects.

Public Instance Methods

[](*args) click to toggle source

Resolves a list of symbols into a path.

# File lib/buildr/core/project.rb, line 70
def [](*args)
  @mapping[args.map(&:to_sym)]
end
[]=(*args) click to toggle source

Specifies the path resolved from a list of symbols.

# File lib/buildr/core/project.rb, line 75
def []=(*args)
  @mapping[args[0...-1].map(&:to_sym)] = args.last
end
expand(*args) click to toggle source

Expands list of symbols and path names into a full path, for example:

puts default.expand(:source, :main, :java)
=> "src/main/java"
# File lib/buildr/core/project.rb, line 62
def expand(*args)
  args = args.compact.reject { |s| s.to_s.empty? }.map(&:to_sym)
  return '' if args.empty?
  @mapping[args] ||= File.join(*[expand(*args[0..-2]), args.last.to_s].reject(&:empty?)) if args.size > 1
  return @mapping[args] || args.first.to_s
end
initialize_copy(copy) click to toggle source
# File lib/buildr/core/project.rb, line 79
def initialize_copy(copy)
  copy.instance_variable_set :@mapping, @mapping.clone
end