Class: Jake::Build

Inherits:
Object
  • Object
show all
Includes:
Enumerable, Eventful
Defined in:
lib/jake/build.rb

Constant Summary collapse

DEFAULT_LAYOUT =
'together'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dir, options = {}) ⇒ Build

Returns a new instance of Build.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/jake/build.rb', line 9

def initialize(dir, options = {})
  @dir    = File.expand_path(dir)
  @helper = Helper.new(options)
  force! if options[:force]
  
  path    = Jake.path(dir, CONFIG_FILE)
  yaml    = File.read(path)
  
  @config_files = [path]
  @config = Jake.symbolize_hash( YAML.load(Jake.erb(yaml).result(@helper.scope)) )
  
  helpers = Jake.path(dir, HELPER_FILE)
  if File.file?(helpers)
    load helpers
    @config_files << helpers
  end
  
  @builds = @config[:builds] || {:src => false, :min => @config[:packer]}
  
  @packages = @config[:packages].inject({}) do |pkgs, (name, conf)|
    pkgs[name] = Package.new(self, name, conf)
    pkgs
  end
  
  @bundles = (@config[:bundles] || {}).inject({}) do |pkgs, (name, conf)|
    pkgs[name] = Bundle.new(self, name, conf)
    pkgs
  end
end

Instance Attribute Details

#config_filesObject (readonly)

Returns the value of attribute config_files.



5
6
7
# File 'lib/jake/build.rb', line 5

def config_files
  @config_files
end

#helperObject (readonly)

Returns the value of attribute helper.



5
6
7
# File 'lib/jake/build.rb', line 5

def helper
  @helper
end

Instance Method Details

#build_directoryObject Also known as: build_dir



70
71
72
# File 'lib/jake/build.rb', line 70

def build_directory
  Jake.path(@dir, @config[:build_directory] || '.')
end

#each(&block) ⇒ Object



39
40
41
# File 'lib/jake/build.rb', line 39

def each(&block)
  @builds.each(&block)
end

#force!Object



43
44
45
# File 'lib/jake/build.rb', line 43

def force!
  @forced = true
end

#forced?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/jake/build.rb', line 47

def forced?
  defined?(@forced)
end

#headerObject



80
81
82
83
84
# File 'lib/jake/build.rb', line 80

def header
  @config[:header] ?
      Jake.read(Jake.path(source_directory, @config[:header])) :
      ""
end

#layoutObject



98
99
100
# File 'lib/jake/build.rb', line 98

def layout
  @config[:layout] || DEFAULT_LAYOUT
end

#package(name) ⇒ Object



58
59
60
# File 'lib/jake/build.rb', line 58

def package(name)
  @packages[name.to_sym] || @bundles[name.to_sym]
end

#packagesObject



51
52
53
54
55
56
# File 'lib/jake/build.rb', line 51

def packages
  list = []
  @packages.each { |name, pkg| list << name }
  @bundles.each  { |name, pkg| list << name }
  list
end

#packer_settings(build_name) ⇒ Object



86
87
88
89
90
# File 'lib/jake/build.rb', line 86

def packer_settings(build_name)
  build = @builds[build_name.to_sym]
  return false unless build
  build[:packer].nil? ? build : build[:packer]
end

#run!Object



62
63
64
65
66
67
68
# File 'lib/jake/build.rb', line 62

def run!
  FileUtils.cd(@dir) do
    @packages.each { |name, pkg| pkg.write! }
    @bundles.each  { |name, pkg| pkg.write! }
    fire(:build_complete)
  end
end

#source_directoryObject Also known as: source_dir



75
76
77
# File 'lib/jake/build.rb', line 75

def source_directory
  Jake.path(@dir, @config[:source_directory] || '.')
end

#use_suffix?(build_name) ⇒ Boolean

Returns:

  • (Boolean)


92
93
94
95
96
# File 'lib/jake/build.rb', line 92

def use_suffix?(build_name)
  build = @builds[build_name.to_sym]
  return true unless build
  build[:suffix] != false
end