Class: Bake::Project

Inherits:
Target show all
Defined in:
lib/bake/target.rb

Constant Summary collapse

SCHEME =
nil

Instance Attribute Summary collapse

Attributes inherited from Target

#children, #deps, #name, #parent

Instance Method Summary collapse

Methods inherited from Target

#child, #dep, #to_s

Methods included from Configuration

#[], #default, #get, #has_prop?, #is?, #opt, #req

Constructor Details

#initialize(parent) ⇒ Project

Returns a new instance of Project.



71
72
73
74
# File 'lib/bake/target.rb', line 71

def initialize(parent)
    super(parent)
    @mappings = {}
end

Instance Attribute Details

#loaderObject

Returns the value of attribute loader.



69
70
71
# File 'lib/bake/target.rb', line 69

def loader
  @loader
end

Instance Method Details

#find(name) ⇒ Object



105
106
107
108
109
110
111
112
# File 'lib/bake/target.rb', line 105

def find(name)
    target = mapping(name)
    target ||= children.find do |child|
        !child.is_a?(Project) && child.name == name
    end
    target ||= parent.find(name) if parent
    return target
end

#map(mappings) ⇒ Object



76
77
78
79
80
81
# File 'lib/bake/target.rb', line 76

def map(mappings)
    mappings.each do |name, loc|
        raise "target '#{name}' already mapped" if @mappings[name]
        @mappings[name] = loc
    end
end

#mapping(name) ⇒ Object



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/bake/target.rb', line 83

def mapping(name)
    target = nil
    mapping = @mappings[name]
    if mapping
        if mapping.instance_of?(String)
            path = @mappings[name].split('/')
            proj = self
            path.each do |dir|
                proj = loader.load_project(dir, proj)
            end
            target = proj.child(name)
            @mappings[name] = target
            raise "invalid mapping #{@mappings[name]}" if !target
        elsif mapping.is_a?(Target)
            target = mapping
        else
            raise "mapping has invalid class '#{mapping.class.name}'"
        end
    end
    return target
end