Class: Buildr::Layout

Inherits:
Object show all
Defined in:
lib/buildr/core/project.rb

Overview

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

Direct Known Subclasses

Default

Defined Under Namespace

Classes: Default

Class Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeLayout

:nodoc:



59
60
61
# File 'lib/buildr/core/project.rb', line 59

def initialize #:nodoc:
  @mapping = {}
end

Class Attribute Details

.defaultObject

Default layout used by new projects.



55
56
57
# File 'lib/buildr/core/project.rb', line 55

def default
  @default
end

Instance Method Details

#[](*args) ⇒ Object

Resolves a list of symbols into a path.



74
75
76
# File 'lib/buildr/core/project.rb', line 74

def [](*args)
  @mapping[args.map(&:to_sym)]
end

#[]=(*args) ⇒ Object

Specifies the path resolved from a list of symbols.



79
80
81
# File 'lib/buildr/core/project.rb', line 79

def []=(*args)
  @mapping[args[0...-1].map(&:to_sym)] = args.last
end

#expand(*args) ⇒ Object

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

puts default.expand(:source, :main, :java)
=> "src/main/java"


66
67
68
69
70
71
# File 'lib/buildr/core/project.rb', line 66

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) ⇒ Object



83
84
85
# File 'lib/buildr/core/project.rb', line 83

def initialize_copy(copy)
  copy.instance_variable_set :@mapping, @mapping.clone
end