Class: Buildr::Layout
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
Defined Under Namespace
Classes: Default
Class Attribute Summary collapse
-
.default ⇒ Object
Default layout used by new projects.
Instance Method Summary collapse
-
#[](*args) ⇒ Object
Resolves a list of symbols into a path.
-
#[]=(*args) ⇒ Object
Specifies the path resolved from a list of symbols.
-
#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”.
-
#initialize ⇒ Layout
constructor
:nodoc:.
- #initialize_copy(copy) ⇒ Object
Constructor Details
#initialize ⇒ Layout
:nodoc:
59 60 61 |
# File 'lib/buildr/core/project.rb', line 59 def initialize #:nodoc: @mapping = {} end |
Class Attribute Details
.default ⇒ Object
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 (*args) args = args.compact.reject { |s| s.to_s.empty? }.map(&:to_sym) return '' if args.empty? @mapping[args] ||= File.join(*[(*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 |