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/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, UnopenedFile
Constant Summary
- VERSION =
"0.5.0"- @@tmp_id =
0
Instance Attribute Summary (collapse)
-
- (Array<FileWrapper>) input_files
(also: #eligible_input_files)
If you specify a glob for #input_glob, this method will calculate the input files for the directory.
-
- (String) input_glob
A glob representing the input files.
-
- (String) input_root
The directory path for the input files.
-
- (Array<FileWrapper>) output_files
readonly
A list of the output files that invoking this pipeline will generate.
-
- (String) output_root
The directory path for the output files.
-
- (Array) rake_tasks
readonly
An Array of Rake::Task objects.
-
- (String) tmpdir
The directory path for temporary files.
Class Method Summary (collapse)
-
+ (Rake::Pipeline) build(&block)
Build a new pipeline taking a block.
Instance Method Summary (collapse)
-
- (void) add_filters(*filters)
(also: #add_filter)
Add one or more filters to the current pipeline.
-
- (Pipeline) copy(target_class = self.class, &block)
private
Copy the current pipeline's attributes over.
-
- (Pipeline) initialize
constructor
A new instance of Pipeline.
-
- (void) invoke
Invoke the pipeline, processing the inputs into the output.
-
- (void) invoke_clean
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.
-
- (void) rake_application=(rake_application)
Set the rake_application on the pipeline and apply it to filters.
-
- (void) setup
private
Set up the filters and generate rake tasks.
Constructor Details
- (Pipeline) initialize
A new instance of Pipeline
119 120 121 122 123 |
# File 'lib/rake-pipeline.rb', line 119 def initialize @filters = [] @tmpdir = "tmp" @mutex = Mutex.new end |
Instance Attribute Details
- (Array<FileWrapper>) input_files 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.
195 196 197 198 199 200 201 202 203 204 205 206 207 |
# File 'lib/rake-pipeline.rb', line 195 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 |
- (String) input_glob
A glob representing the input files
97 98 99 |
# File 'lib/rake-pipeline.rb', line 97 def input_glob @input_glob end |
- (String) input_root
The directory path for the input files.
100 101 102 |
# File 'lib/rake-pipeline.rb', line 100 def input_root @input_root end |
- (Array<FileWrapper>) output_files (readonly)
A list of the output files that invoking this pipeline will generate.
115 116 117 |
# File 'lib/rake-pipeline.rb', line 115 def output_files @filters.last.output_files unless @filters.empty? end |
- (String) output_root
The directory path for the output files.
103 104 105 |
# File 'lib/rake-pipeline.rb', line 103 def output_root @output_root end |
- (Array) rake_tasks (readonly)
An Array of Rake::Task objects. This property is populated by the #generate_rake_tasks method.
111 112 113 |
# File 'lib/rake-pipeline.rb', line 111 def rake_tasks @rake_tasks end |
- (String) tmpdir
The directory path for temporary files.
106 107 108 |
# File 'lib/rake-pipeline.rb', line 106 def tmpdir @tmpdir end |
Class Method Details
+ (Rake::Pipeline) build(&block)
Build a new pipeline taking a block. The block will be evaluated by the Rake::Pipeline::DSL class.
143 144 145 146 147 |
# File 'lib/rake-pipeline.rb', line 143 def self.build(&block) pipeline = new DSL.evaluate(pipeline, &block) if block pipeline end |
Instance Method Details
- (void) add_filters(*filters) Also known as: add_filter
This method returns an undefined value.
Add one or more filters to the current pipeline.
232 233 234 235 |
# File 'lib/rake-pipeline.rb', line 232 def add_filters(*filters) filters.each { |filter| filter.rake_application = rake_application } @filters.concat(filters) end |
- (Pipeline) copy(target_class = self.class, &block)
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.
159 160 161 162 163 164 165 |
# File 'lib/rake-pipeline.rb', line 159 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 |
- (void) invoke
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.
243 244 245 246 247 248 249 250 251 252 |
# File 'lib/rake-pipeline.rb', line 243 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 |
- (void) invoke_clean
This method returns an undefined value.
Pick up any new files added to the inputs and process them through the filters. Then call #invoke.
258 259 260 261 |
# File 'lib/rake-pipeline.rb', line 258 def invoke_clean @rake_tasks = @rake_application = nil invoke end |
- (Rake::Application) rake_application
The Rake::Application to install rake tasks onto. Defaults to Rake.application
215 216 217 |
# File 'lib/rake-pipeline.rb', line 215 def rake_application @rake_application || Rake.application end |
- (void) rake_application=(rake_application)
This method returns an undefined value.
Set the rake_application on the pipeline and apply it to filters.
222 223 224 225 226 |
# File 'lib/rake-pipeline.rb', line 222 def rake_application=(rake_application) @rake_application = rake_application @filters.each { |filter| filter.rake_application = rake_application } @rake_tasks = nil end |
- (void) setup
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.
268 269 270 271 |
# File 'lib/rake-pipeline.rb', line 268 def setup setup_filters generate_rake_tasks end |