Class: Rake::Pipeline::Project
- Inherits:
-
Object
- Object
- Rake::Pipeline::Project
- Defined in:
- lib/rake-pipeline/project.rb
Overview
A Project controls the lifecycle of a series of Pipelines, creating them from an Assetfile and recreating them if the Assetfile changes.
Instance Attribute Summary collapse
-
#after_filters ⇒ Array
writeonly
A list of filters to be applied after the specified filters in every pipeline.
-
#assetfile_digest ⇒ String|nil
readonly
The digest of the Assetfile the project was created with, or nil if the project was created without an Assetfile.
-
#assetfile_path ⇒ String|nil
readonly
The path to the project’s Assetfile or nil if it was created without an Assetfile.
-
#before_filters ⇒ Array
writeonly
A list of filters to be applied before the specified filters in every pipeline.
-
#default_output_root ⇒ String
The directory path where pipelines will write their outputs by default.
-
#maps ⇒ Object
readonly
Returns the value of attribute maps.
-
#pipelines ⇒ Pipeline
readonly
The list of pipelines in the project.
-
#tmpdir ⇒ String
The directory path for temporary files.
Class Method Summary collapse
-
.add_to_digest(str) ⇒ Object
Add a value to the list of strings to append to the digest temp directory.
-
.build(&block) ⇒ Rake::Pipeline::Project
Configure a new project by evaluating a block with the Rake::Pipeline::DSL::ProjectDSL class.
-
.digest_additions ⇒ Array[String]
An array of strings that will be appended to #digested_tmpdir.
-
.digest_additions=(additions) ⇒ Object
Set Project.digest_additions to a sorted copy of the given array.
Instance Method Summary collapse
-
#build(&block) ⇒ Object
Evaluate a block using the Rake::Pipeline::DSL::ProjectDSL DSL against an existing project.
-
#build_pipeline(input, glob = nil, &block) ⇒ Object
Build a new pipeline and add it to our list of pipelines.
-
#clean ⇒ Object
Remove the project’s temporary and output files.
-
#cleanup_tmpdir ⇒ void
Clean out old tmp directories from the pipeline’s #tmpdir.
-
#digested_tmpdir ⇒ String
A subdirectory of #tmpdir with the digest of the Assetfile’s contents and any Project.digest_additions in its name.
- #files_to_clean ⇒ Object
-
#initialize(assetfile_or_pipeline = nil) ⇒ Project
constructor
A new instance of Project.
-
#invoke ⇒ void
Invoke all of the project’s pipelines, detecting any changes to the Assetfile and rebuilding the pipelines if necessary.
-
#last_manifest ⇒ Manifest
The manifest to write dependency information to.
-
#manifest ⇒ Manifest
The manifest to write dependency information to.
-
#manifest_path ⇒ String
The path to the dynamic dependency manifest.
- #obsolete_tmpdirs ⇒ Object
-
#output_files ⇒ Array[FileWrapper]
A list of the files that will be generated when this project is invoked.
Constructor Details
#initialize(assetfile_or_pipeline = nil) ⇒ Project
Returns a new instance of Project.
89 90 91 92 93 94 95 96 97 |
# File 'lib/rake-pipeline/project.rb', line 89 def initialize(assetfile_or_pipeline=nil) reset! if assetfile_or_pipeline.kind_of?(String) @assetfile_path = File.(assetfile_or_pipeline) rebuild_from_assetfile(@assetfile_path) elsif assetfile_or_pipeline @pipelines << assetfile_or_pipeline end end |
Instance Attribute Details
#after_filters=(value) ⇒ Array (writeonly)
Returns a list of filters to be applied after the specified filters in every pipeline.
36 37 38 |
# File 'lib/rake-pipeline/project.rb', line 36 def after_filters=(value) @after_filters = value end |
#assetfile_digest ⇒ String|nil (readonly)
Returns the digest of the Assetfile the project was created with, or nil if the project was created without an Assetfile.
21 22 23 |
# File 'lib/rake-pipeline/project.rb', line 21 def assetfile_digest @assetfile_digest end |
#assetfile_path ⇒ String|nil (readonly)
Returns the path to the project’s Assetfile or nil if it was created without an Assetfile.
16 17 18 |
# File 'lib/rake-pipeline/project.rb', line 16 def assetfile_path @assetfile_path end |
#before_filters=(value) ⇒ Array (writeonly)
Returns a list of filters to be applied before the specified filters in every pipeline.
32 33 34 |
# File 'lib/rake-pipeline/project.rb', line 32 def before_filters=(value) @before_filters = value end |
#default_output_root ⇒ String
Returns the directory path where pipelines will write their outputs by default.
28 29 30 |
# File 'lib/rake-pipeline/project.rb', line 28 def default_output_root @default_output_root end |
#maps ⇒ Object (readonly)
Returns the value of attribute maps.
12 13 14 |
# File 'lib/rake-pipeline/project.rb', line 12 def maps @maps end |
#pipelines ⇒ Pipeline (readonly)
Returns the list of pipelines in the project.
10 11 12 |
# File 'lib/rake-pipeline/project.rb', line 10 def pipelines @pipelines end |
#tmpdir ⇒ String
Returns the directory path for temporary files.
24 25 26 |
# File 'lib/rake-pipeline/project.rb', line 24 def tmpdir @tmpdir end |
Class Method Details
.add_to_digest(str) ⇒ Object
Add a value to the list of strings to append to the digest temp directory. Libraries can use this to add (for example) their version numbers so that the pipeline will be rebuilt if the library version changes.
80 81 82 83 |
# File 'lib/rake-pipeline/project.rb', line 80 def add_to_digest(str) self.digest_additions << str.to_s self.digest_additions.sort! end |
.build(&block) ⇒ Rake::Pipeline::Project
Configure a new project by evaluating a block with the Rake::Pipeline::DSL::ProjectDSL class.
55 56 57 58 |
# File 'lib/rake-pipeline/project.rb', line 55 def build(&block) project = new project.build(&block) end |
.digest_additions ⇒ Array[String]
Returns an array of strings that will be appended to #digested_tmpdir.
62 63 64 |
# File 'lib/rake-pipeline/project.rb', line 62 def digest_additions @digest_additions ||= [] end |
.digest_additions=(additions) ⇒ Object
Set digest_additions to a sorted copy of the given array.
67 68 69 |
# File 'lib/rake-pipeline/project.rb', line 67 def digest_additions=(additions) @digest_additions = additions.sort end |
Instance Method Details
#build(&block) ⇒ Object
Evaluate a block using the Rake::Pipeline::DSL::ProjectDSL DSL against an existing project.
101 102 103 104 |
# File 'lib/rake-pipeline/project.rb', line 101 def build(&block) DSL::ProjectDSL.evaluate(self, &block) if block self end |
#build_pipeline(input, glob = nil, &block) ⇒ Object
Build a new pipeline and add it to our list of pipelines.
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 |
# File 'lib/rake-pipeline/project.rb', line 199 def build_pipeline(input, glob=nil, &block) pipeline = Rake::Pipeline.build({ :before_filters => @before_filters, :after_filters => @after_filters, :output_root => default_output_root, :tmpdir => digested_tmpdir, :project => self }, &block) if input.kind_of?(Array) input.each { |x| pipeline.add_input(x) } elsif input.kind_of?(Hash) pipeline.inputs = input else pipeline.add_input(input, glob) end @pipelines << pipeline pipeline end |
#clean ⇒ Object
Remove the project’s temporary and output files.
134 135 136 137 |
# File 'lib/rake-pipeline/project.rb', line 134 def clean last_manifest.clear files_to_clean.each { |file| FileUtils.rm_rf(file) } end |
#cleanup_tmpdir ⇒ void
This method returns an undefined value.
Clean out old tmp directories from the pipeline’s Rake::Pipeline#tmpdir.
143 144 145 |
# File 'lib/rake-pipeline/project.rb', line 143 def cleanup_tmpdir obsolete_tmpdirs.each { |dir| FileUtils.rm_rf(dir) } end |
#digested_tmpdir ⇒ String
Returns A subdirectory of #tmpdir with the digest of the Assetfile’s contents and any digest_additions in its name.
164 165 166 167 168 169 170 |
# File 'lib/rake-pipeline/project.rb', line 164 def digested_tmpdir suffix = assetfile_digest unless self.class.digest_additions.empty? suffix += "-#{self.class.digest_additions.join('-')}" end File.join(tmpdir, "rake-pipeline-#{suffix}") end |
#files_to_clean ⇒ Object
186 187 188 189 |
# File 'lib/rake-pipeline/project.rb', line 186 def files_to_clean setup_pipelines obsolete_tmpdirs + [digested_tmpdir] + output_files.map(&:fullpath) end |
#invoke ⇒ void
This method returns an undefined value.
Invoke all of the project’s pipelines, detecting any changes to the Assetfile and rebuilding the pipelines if necessary.
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/rake-pipeline/project.rb', line 111 def invoke @invoke_mutex.synchronize do last_manifest.read_manifest if dirty? rebuild_from_assetfile(assetfile_path) if assetfile_dirty? # The temporary files have to be cleaned otherwise # there will be a "ghost" input. Here's an example # rake task: application.js => [a.js, b.js]. Deleting a.js # will make application.js => [b.js]. The task correctly checks # if B has changed (which it hasn't) and says that application.js # is correct. Cleaning tmp files ensures that this doesn't happen. clean if files_deleted? pipelines.each(&:invoke) manifest.write_manifest end end end |
#last_manifest ⇒ Manifest
Returns the manifest to write dependency information to.
228 229 230 |
# File 'lib/rake-pipeline/project.rb', line 228 def last_manifest @last_manifest ||= Rake::Pipeline::Manifest.new(manifest_path) end |
#manifest ⇒ Manifest
Returns the manifest to write dependency information to.
222 223 224 |
# File 'lib/rake-pipeline/project.rb', line 222 def manifest @manifest ||= Rake::Pipeline::Manifest.new(manifest_path) end |
#manifest_path ⇒ String
Returns the path to the dynamic dependency manifest.
233 234 235 |
# File 'lib/rake-pipeline/project.rb', line 233 def manifest_path File.join(digested_tmpdir, "manifest.json") end |
#obsolete_tmpdirs ⇒ Object
174 175 176 177 178 179 180 181 182 |
# File 'lib/rake-pipeline/project.rb', line 174 def obsolete_tmpdirs if File.directory?(tmpdir) Dir["#{tmpdir}/rake-pipeline-*"].sort.reject do |dir| dir == digested_tmpdir end else [] end end |
#output_files ⇒ Array[FileWrapper]
Returns a list of the files that will be generated when this project is invoked.
193 194 195 196 |
# File 'lib/rake-pipeline/project.rb', line 193 def output_files setup_pipelines pipelines.map(&:output_files).flatten end |