Class: Jake::Build
- Inherits:
-
Object
- Object
- Jake::Build
- Includes:
- Enumerable, Eventful
- Defined in:
- lib/jake/build.rb
Overview
A Build
encapsulates a single instance of running Jake.build!
. It is responsible for running the build and provides access to any configuration data used to set up the build.
Constant Summary collapse
- DEFAULT_LAYOUT =
'together'
Instance Attribute Summary collapse
-
#helper ⇒ Object
readonly
Returns the value of attribute helper.
Instance Method Summary collapse
-
#build_directory ⇒ Object
(also: #build_dir)
Returns the path to the build directory, where generated files appear.
-
#each(&block) ⇒ Object
Yields to the block for each build in the group.
-
#force! ⇒ Object
Forces the build to generate new files even if target files appear up-to-date.
-
#forced? ⇒ Boolean
Returns
true
iff this is a forced build. -
#header ⇒ Object
Returns the header string used for the build, or an empty string if no header file has been set.
-
#initialize(dir, options = {}) ⇒ Build
constructor
Builds are initialized using a directory in which to run the build, and an options hash.
-
#layout ⇒ Object
Returns the name of the layout being used, either
together
orapart
. -
#package(name) ⇒ Object
Returns the
Buildable
with the given name. -
#packages ⇒ Object
Returns a list of names for all packages in the build.
-
#packer_settings(build_name) ⇒ Object
Returns the minification settings for PackR for the given build name.
-
#run! ⇒ Object
Runs the build, generating new files in
build_directory
. -
#source_directory ⇒ Object
(also: #source_dir)
Returns the path to the source directory, where source code is read from.
-
#use_suffix?(build_name) ⇒ Boolean
Returns
true
iff filename suffixes based on build name should be added to generated files for the given build name.
Constructor Details
#initialize(dir, options = {}) ⇒ Build
Builds are initialized using a directory in which to run the build, and an options hash. Options are passed through to helper methods in the options
object.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/jake/build.rb', line 16 def initialize(dir, = {}) @dir = File.(dir) @helper = Helper.new() force! if [:force] path = Jake.path(dir, CONFIG_FILE) yaml = File.read(path) @config = Jake.symbolize_hash( YAML.load(Jake.erb(yaml).result(@helper.scope)) ) helpers = Jake.path(dir, HELPER_FILE) load helpers if File.file?(helpers) @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
#helper ⇒ Object (readonly)
Returns the value of attribute helper.
11 12 13 |
# File 'lib/jake/build.rb', line 11 def helper @helper end |
Instance Method Details
#build_directory ⇒ Object Also known as: build_dir
Returns the path to the build directory, where generated files appear.
80 81 82 |
# File 'lib/jake/build.rb', line 80 def build_directory Jake.path(@dir, @config[:build_directory] || '.') end |
#each(&block) ⇒ Object
Yields to the block for each build in the group.
43 44 45 |
# File 'lib/jake/build.rb', line 43 def each(&block) @builds.each(&block) end |
#force! ⇒ Object
Forces the build to generate new files even if target files appear up-to-date.
48 49 50 |
# File 'lib/jake/build.rb', line 48 def force! @forced = true end |
#forced? ⇒ Boolean
Returns true
iff this is a forced build.
53 54 55 |
# File 'lib/jake/build.rb', line 53 def forced? defined?(@forced) end |
#header ⇒ Object
Returns the header string used for the build, or an empty string if no header file has been set.
93 94 95 96 97 |
# File 'lib/jake/build.rb', line 93 def header @config[:header] ? Jake.read(Jake.path(source_directory, @config[:header])) : "" end |
#layout ⇒ Object
Returns the name of the layout being used, either together
or apart
.
117 118 119 |
# File 'lib/jake/build.rb', line 117 def layout @config[:layout] || DEFAULT_LAYOUT end |
#package(name) ⇒ Object
Returns the Buildable
with the given name.
66 67 68 |
# File 'lib/jake/build.rb', line 66 def package(name) @packages[name.to_sym] || @bundles[name.to_sym] end |
#packages ⇒ Object
Returns a list of names for all packages in the build.
58 59 60 61 62 63 |
# File 'lib/jake/build.rb', line 58 def packages list = [] @packages.each { |name, pkg| list << name } @bundles.each { |name, pkg| list << name } list end |
#packer_settings(build_name) ⇒ Object
Returns the minification settings for PackR for the given build name. Each Build
object can build all its packages multiple times with different minification settings in each run.
102 103 104 105 106 |
# File 'lib/jake/build.rb', line 102 def packer_settings(build_name) build = @builds[build_name.to_sym] return false unless build build[:packer].nil? ? build : build[:packer] end |
#run! ⇒ Object
Runs the build, generating new files in build_directory
.
71 72 73 74 75 76 77 |
# File 'lib/jake/build.rb', line 71 def run! FileUtils.cd(@dir) do @packages.each { |name, pkg| pkg.write! } @bundles.each { |name, pkg| pkg.write! } fire(:build_complete) end end |
#source_directory ⇒ Object Also known as: source_dir
Returns the path to the source directory, where source code is read from.
86 87 88 |
# File 'lib/jake/build.rb', line 86 def source_directory Jake.path(@dir, @config[:source_directory] || '.') end |
#use_suffix?(build_name) ⇒ Boolean
Returns true
iff filename suffixes based on build name should be added to generated files for the given build name.
110 111 112 113 114 |
# File 'lib/jake/build.rb', line 110 def use_suffix?(build_name) build = @builds[build_name.to_sym] return true unless build build[:suffix] != false end |