Class: Rake::Pipeline
- Inherits:
-
Object
- Object
- Rake::Pipeline
- Defined in:
- lib/rake-pipeline.rb,
lib/rake-pipeline/dsl.rb,
lib/rake-pipeline/error.rb,
lib/rake-pipeline/filter.rb,
lib/rake-pipeline/matcher.rb,
lib/rake-pipeline/railtie.rb,
lib/rake-pipeline/version.rb,
lib/rake-pipeline/middleware.rb,
lib/rake-pipeline/file_wrapper.rb,
lib/rake-pipeline/filters/concat.rb
Overview
A Pipeline is responsible for taking a directory of input files, applying a number of filters to the inputs, and outputting them into an output directory.
The normal way to build and configure a pipeline is by using Pipeline.build. Inside the block passed to Pipeline.build, all methods of DSL are available.
Direct Known Subclasses
Defined Under Namespace
Classes: ConcatFilter, DSL, EncodingError, Error, FileWrapper, Filter, Matcher, Middleware, Railtie, UnopenedFile
Constant Summary collapse
- VERSION =
"0.5.0"
- @@tmp_id =
0
Instance Attribute Summary collapse
-
#filters ⇒ Array
readonly
This pipeline’s filters.
-
#input_files ⇒ Array<FileWrapper>
(also: #eligible_input_files)
If you specify a glob for #input_glob, this method will calculate the input files for the directory.
-
#input_glob ⇒ String
A glob representing the input files.
-
#input_root ⇒ String
The directory path for the input files.
-
#output_files ⇒ Array<FileWrapper>
readonly
A list of the output files that invoking this pipeline will generate.
-
#output_root ⇒ String
The directory path for the output files.
-
#rake_tasks ⇒ Array
readonly
An Array of Rake::Task objects.
-
#tmpdir ⇒ String
The directory path for temporary files.
Class Method Summary collapse
-
.build(&block) ⇒ Rake::Pipeline
Build a new pipeline taking a block.
Instance Method Summary collapse
-
#add_filters(*filters) ⇒ void
(also: #add_filter)
Add one or more filters to the current pipeline.
-
#copy(target_class = self.class, &block) ⇒ Pipeline
private
Copy the current pipeline’s attributes over.
-
#initialize ⇒ Pipeline
constructor
A new instance of Pipeline.
-
#invoke ⇒ void
Invoke the pipeline, processing the inputs into the output.
-
#invoke_clean ⇒ void
Pick up any new files added to the inputs and process them through the filters.
-
#rake_application ⇒ Rake::Application
The Rake::Application to install rake tasks onto.
-
#rake_application=(rake_application) ⇒ void
Set the rake_application on the pipeline and apply it to filters.
-
#setup ⇒ void
private
Set up the filters and generate rake tasks.
Constructor Details
#initialize ⇒ Pipeline
Returns a new instance of Pipeline.
129 130 131 132 133 |
# File 'lib/rake-pipeline.rb', line 129 def initialize @filters = [] @tmpdir = "tmp" @mutex = Mutex.new end |
Instance Attribute Details
#filters ⇒ Array (readonly)
Returns this pipeline’s filters.
125 126 127 |
# File 'lib/rake-pipeline.rb', line 125 def filters @filters end |
#input_files ⇒ Array<FileWrapper> Also known as: eligible_input_files
If you specify a glob for #input_glob, this method will calculate the input files for the directory. If you supply input_files directly, this method will simply return the input_files you supplied.
205 206 207 208 209 210 211 212 213 214 215 216 217 |
# File 'lib/rake-pipeline.rb', line 205 def input_files return @input_files if @input_files assert_input_provided = File.(input_root) files = Dir[File.join(, input_glob)].select { |f| File.file?(f) } files.map do |file| relative_path = file.sub(%r{^#{Regexp.escape()}/}, '') FileWrapper.new(, relative_path) end end |
#input_glob ⇒ String
Returns a glob representing the input files.
104 105 106 |
# File 'lib/rake-pipeline.rb', line 104 def input_glob @input_glob end |
#input_root ⇒ String
Returns the directory path for the input files.
107 108 109 |
# File 'lib/rake-pipeline.rb', line 107 def input_root @input_root end |
#output_files ⇒ Array<FileWrapper> (readonly)
A list of the output files that invoking this pipeline will generate.
122 123 124 |
# File 'lib/rake-pipeline.rb', line 122 def output_files @output_files end |
#output_root ⇒ String
Returns the directory path for the output files.
110 111 112 |
# File 'lib/rake-pipeline.rb', line 110 def output_root @output_root end |
#rake_tasks ⇒ Array (readonly)
Returns an Array of Rake::Task objects. This property is populated by the #generate_rake_tasks method.
118 119 120 |
# File 'lib/rake-pipeline.rb', line 118 def rake_tasks @rake_tasks end |
#tmpdir ⇒ String
Returns the directory path for temporary files.
113 114 115 |
# File 'lib/rake-pipeline.rb', line 113 def tmpdir @tmpdir end |
Class Method Details
.build(&block) ⇒ Rake::Pipeline
Build a new pipeline taking a block. The block will be evaluated by the Rake::Pipeline::DSL class.
153 154 155 156 157 |
# File 'lib/rake-pipeline.rb', line 153 def self.build(&block) pipeline = new DSL.evaluate(pipeline, &block) if block pipeline end |
Instance Method Details
#add_filters(*filters) ⇒ void Also known as: add_filter
This method returns an undefined value.
Add one or more filters to the current pipeline.
242 243 244 245 |
# File 'lib/rake-pipeline.rb', line 242 def add_filters(*filters) filters.each { |filter| filter.rake_application = rake_application } @filters.concat(filters) end |
#copy(target_class = self.class, &block) ⇒ Pipeline
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Copy the current pipeline’s attributes over.
169 170 171 172 173 174 175 |
# File 'lib/rake-pipeline.rb', line 169 def copy(target_class=self.class, &block) pipeline = target_class.build(&block) pipeline.input_root = input_root pipeline.tmpdir = tmpdir pipeline.rake_application = rake_application pipeline end |
#invoke ⇒ void
This method returns an undefined value.
Invoke the pipeline, processing the inputs into the output. If the pipeline has already been invoked, reinvoking will not pick up new input files added to the file system.
253 254 255 256 257 258 259 260 261 262 |
# File 'lib/rake-pipeline.rb', line 253 def invoke @mutex.synchronize do self.rake_application = Rake::Application.new unless @rake_application setup @rake_tasks.each { |task| task.recursively_reenable(rake_application) } @rake_tasks.each { |task| task.invoke } end end |
#invoke_clean ⇒ void
This method returns an undefined value.
Pick up any new files added to the inputs and process them through the filters. Then call #invoke.
268 269 270 271 |
# File 'lib/rake-pipeline.rb', line 268 def invoke_clean @rake_tasks = @rake_application = nil invoke end |
#rake_application ⇒ Rake::Application
Returns The Rake::Application to install rake tasks onto. Defaults to Rake.application.
225 226 227 |
# File 'lib/rake-pipeline.rb', line 225 def rake_application @rake_application || Rake.application end |
#rake_application=(rake_application) ⇒ void
This method returns an undefined value.
Set the rake_application on the pipeline and apply it to filters.
232 233 234 235 236 |
# File 'lib/rake-pipeline.rb', line 232 def rake_application=(rake_application) @rake_application = rake_application @filters.each { |filter| filter.rake_application = rake_application } @rake_tasks = nil end |
#setup ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Set up the filters and generate rake tasks. In general, this method is called by invoke.
278 279 280 281 |
# File 'lib/rake-pipeline.rb', line 278 def setup setup_filters generate_rake_tasks end |