Class: BrickAndMortar::Project

Inherits:
Object
  • Object
show all
Defined in:
lib/brick_and_mortar/project.rb

Constant Summary collapse

DEFAULT_BRICK_STORE =
File.join(Dir.home, '.bricks')

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(brickfile, brick_store = DEFAULT_BRICK_STORE) ⇒ Project

Returns a new instance of Project.



10
11
12
13
14
15
# File 'lib/brick_and_mortar/project.rb', line 10

def initialize(brickfile, brick_store = DEFAULT_BRICK_STORE)
  @config = Config.new brick_store
  @config.create_store!
  @bricks = @config.parse_file! brickfile
  @project_root = File.dirname(brickfile)
end

Instance Attribute Details

#bricksObject (readonly)

Returns the value of attribute bricks.



6
7
8
# File 'lib/brick_and_mortar/project.rb', line 6

def bricks
  @bricks
end

#configObject (readonly)

Returns the value of attribute config.



6
7
8
# File 'lib/brick_and_mortar/project.rb', line 6

def config
  @config
end

#project_rootObject (readonly)

Returns the value of attribute project_root.



6
7
8
# File 'lib/brick_and_mortar/project.rb', line 6

def project_root
  @project_root
end

Instance Method Details

#laid?Boolean

Returns:

  • (Boolean)


21
22
23
24
25
26
# File 'lib/brick_and_mortar/project.rb', line 21

def laid?
  @bricks.reduce(File.exist?(vendor)) do |has_been_laid, brick|
    break has_been_laid unless has_been_laid
    has_been_laid && brick.laid?(vendor)
  end
end

#lay!Object



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/brick_and_mortar/project.rb', line 28

def lay!
  FileUtils.mkpath vendor
  @bricks.each do |b|
    b.lay! vendor
    sub_brickfile = File.join(b.destination, 'Brickfile')
    if File.file?(sub_brickfile)
      Dir.chdir(b.destination) do |dir|
        subproject = Project.new(sub_brickfile, @config.store)
        subproject.lay!
      end
    end
  end
end

#vendorObject



17
18
19
# File 'lib/brick_and_mortar/project.rb', line 17

def vendor
  File.join(@project_root, 'vendor')
end