Class: Bake::Project
Instance Attribute Summary collapse
-
#loader ⇒ Object
readonly
Returns the value of attribute loader.
Attributes inherited from Target
#children, #deps, #name, #parent, #posts, #toolset
Instance Method Summary collapse
- #child_project(name) ⇒ Object
- #current_project ⇒ Object
- #map(mappings) ⇒ Object
- #parent_project ⇒ Object
- #post_initialize(loader) ⇒ Object
-
#resolve(path) ⇒ Object
Returns the target found at
path
relative to this project.
Methods inherited from Target
#add_dep, #build_r, #built?, #clean, #clean_r, #dep, #initialize, #mtimes, #post, #products, #stale?, #to_s
Methods included from Configuration
#[], #default, #get, #has_prop?, #is?, #opt
Constructor Details
This class inherits a constructor from Bake::Target
Instance Attribute Details
#loader ⇒ Object (readonly)
Returns the value of attribute loader.
5 6 7 |
# File 'lib/bake/project.rb', line 5 def loader @loader end |
Instance Method Details
#child_project(name) ⇒ Object
20 21 22 23 24 25 |
# File 'lib/bake/project.rb', line 20 def child_project(name) child = children.find do |child| child.name == name && child.is_a?(Project) end return child || loader.load_project(self, name) end |
#current_project ⇒ Object
12 13 14 |
# File 'lib/bake/project.rb', line 12 def current_project return self end |
#map(mappings) ⇒ Object
27 28 29 |
# File 'lib/bake/project.rb', line 27 def map(mappings) @mappings.merge!(mappings) end |
#parent_project ⇒ Object
16 17 18 |
# File 'lib/bake/project.rb', line 16 def parent_project return parent ? parent.current_project : nil end |
#post_initialize(loader) ⇒ Object
7 8 9 10 |
# File 'lib/bake/project.rb', line 7 def post_initialize(loader) @loader = loader @mappings = {} end |
#resolve(path) ⇒ Object
Returns the target found at path
relative to this project. Raises a RuntimeError
if no such target is found.
The path
argument is of the form:
<dir>:<name> | <name> | <dir>
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/bake/project.rb', line 36 def resolve(path) search_projects = ([ self ] + get(:search_projects)) index = path.index(':') if index # search for a fully qualified target given by dir:name dir = path.slice(0, index) name = path.slice(index + 1, path.length - index - 1) else if !path.index('/') && path != '.' && path != '..' # search for target named by path in search_projects target = nil search_projects.each do |proj| target = proj.find_target(path) return target if target end end # search for a project at given path dir = path name = nil end # iterate the search_projects looking for target given by dir:name search_projects.each do |proj| dir.split('/').each do |el| if el == '.' next elsif el == '..' proj = proj.parent_project break if !proj else begin proj = proj.child_project(el) rescue ProjectLoadError proj = nil break end end end # found a project at dir, find a child named name if proj return proj if !name target = proj.find_target(name) return target if target end end raise "invalid target path '#{path}'" end |