Class: Rake::Pipeline::DSL::PipelineDSL
- Inherits:
-
Object
- Object
- Rake::Pipeline::DSL::PipelineDSL
- Defined in:
- lib/rake-pipeline/dsl/pipeline_dsl.rb
Overview
This class is used by ProjectDSL to provide a convenient DSL for configuring a pipeline.
All instance methods of PipelineDSL are available in the context the block passed to Rake::Pipeline.
Rake::Pipeline.build.
Instance Attribute Summary collapse
-
#pipeline ⇒ Pipeline
readonly
The pipeline the DSL should configure.
Class Method Summary collapse
-
.evaluate(pipeline, options, &block) ⇒ void
Configure a pipeline with a passed in block.
Instance Method Summary collapse
-
#concat(*args, &block) ⇒ Object
(also: #copy)
A helper method for adding a concat filter to the pipeline.
-
#filter(filter_class, *ctor_args, &block) ⇒ void
Add a filter to the pipeline.
-
#gsub(*args, &block) ⇒ Object
(also: #replace)
A helper method for adding a gsub filter to the pipeline.
-
#initialize(pipeline) ⇒ void
constructor
Create a new PipelineDSL to configure a pipeline.
-
#input(root, glob = "**/*") ⇒ void
Add an input location and files to a pipeline.
-
#match(pattern, &block) ⇒ Matcher
Apply a number of filters, but only to files matching a particular pattern.
-
#output(root) ⇒ void
Specify the output directory for the pipeline.
-
#reject(pattern = '', &block) ⇒ RejectMatcher
(also: #exclude, #skip)
Reject files matching a pattern or block.
-
#sort(&block) ⇒ SortedPipeline
Apply filters in a sorted fashion.
-
#strip(matcher) ⇒ Object
A helper method like gsub, but removes everything specified by the matcher.
Constructor Details
#initialize(pipeline) ⇒ void
Create a new Rake::Pipeline::DSL::PipelineDSL to configure a pipeline.
53 54 55 |
# File 'lib/rake-pipeline/dsl/pipeline_dsl.rb', line 53 def initialize(pipeline) @pipeline = pipeline end |
Instance Attribute Details
#pipeline ⇒ Pipeline (readonly)
Returns the pipeline the DSL should configure.
11 12 13 |
# File 'lib/rake-pipeline/dsl/pipeline_dsl.rb', line 11 def pipeline @pipeline end |
Class Method Details
.evaluate(pipeline, options, &block) ⇒ void
This method returns an undefined value.
Configure a pipeline with a passed in block.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/rake-pipeline/dsl/pipeline_dsl.rb', line 21 def self.evaluate(pipeline, , &block) dsl = new(pipeline) # If any before filters, apply them to the pipeline. # They will be run in reverse of insertion order. if before_filters = [:before_filters] before_filters.each do |klass, args, block| dsl.filter klass, *args, &block end end # Evaluate the block in the context of the DSL. dsl.instance_eval(&block) # If any after filters, apply them to the pipeline. # They will be run in insertion order. if after_filters = [:after_filters] after_filters.each do |klass, args, block| dsl.filter klass, *args, &block end end # the FinalizingFilter should always come after all # user specified after filters pipeline.finalize end |
Instance Method Details
#concat(*args, &block) ⇒ Object Also known as: copy
A helper method for adding a concat filter to the pipeline. If the first argument is an Array, it adds a new OrderingConcatFilter, otherwise it adds a new ConcatFilter.
218 219 220 221 222 223 224 |
# File 'lib/rake-pipeline/dsl/pipeline_dsl.rb', line 218 def concat(*args, &block) if args.first.kind_of?(Array) filter(Rake::Pipeline::OrderingConcatFilter, *args, &block) else filter(Rake::Pipeline::ConcatFilter, *args, &block) end end |
#filter(filter_class, *ctor_args, &block) ⇒ void
This method returns an undefined value.
Add a filter to the pipeline.
In addition to a filter class, #filter takes a block that describes how the filter should map input files to output files.
By default, the block maps an input file into an output file with the same name.
Any additional arguments passed to #filter will be passed on to the filter class’s constructor.
99 100 101 102 |
# File 'lib/rake-pipeline/dsl/pipeline_dsl.rb', line 99 def filter(filter_class, *ctor_args, &block) filter = filter_class.new(*ctor_args, &block) pipeline.add_filter(filter) end |
#gsub(*args, &block) ⇒ Object Also known as: replace
A helper method for adding a gsub filter to the pipeline.
230 231 232 |
# File 'lib/rake-pipeline/dsl/pipeline_dsl.rb', line 230 def gsub(*args, &block) filter(Rake::Pipeline::GsubFilter, *args, &block) end |
#input(root, glob = "**/*") ⇒ void
This method returns an undefined value.
Add an input location and files to a pipeline.
74 75 76 |
# File 'lib/rake-pipeline/dsl/pipeline_dsl.rb', line 74 def input(root, glob="**/*") pipeline.add_input root, glob end |
#match(pattern, &block) ⇒ Matcher
Apply a number of filters, but only to files matching a particular pattern.
Inside the block passed to match, you may specify any number of filters that should be applied to files matching the pattern.
134 135 136 137 138 139 |
# File 'lib/rake-pipeline/dsl/pipeline_dsl.rb', line 134 def match(pattern, &block) matcher = pipeline.copy(Matcher, &block) matcher.glob = pattern pipeline.add_filter matcher matcher end |
#output(root) ⇒ void
This method returns an undefined value.
Specify the output directory for the pipeline.
206 207 208 |
# File 'lib/rake-pipeline/dsl/pipeline_dsl.rb', line 206 def output(root) pipeline.output_root = root end |
#reject(pattern = '', &block) ⇒ RejectMatcher Also known as: exclude, skip
Reject files matching a pattern or block. You may specify a glob or a glob.
true will skip that file.
165 166 167 168 169 170 171 |
# File 'lib/rake-pipeline/dsl/pipeline_dsl.rb', line 165 def reject(pattern = '', &block) matcher = pipeline.copy(RejectMatcher) matcher.glob = pattern matcher.block = block pipeline.add_filter matcher matcher end |
#sort(&block) ⇒ SortedPipeline
Apply filters in a sorted fashion. Use this when you need something other than file name ordering.
195 196 197 198 199 200 |
# File 'lib/rake-pipeline/dsl/pipeline_dsl.rb', line 195 def sort(&block) sorter = pipeline.copy(SortedPipeline) sorter.comparator = block pipeline.add_filter sorter sorter end |
#strip(matcher) ⇒ Object
A helper method like gsub, but removes everything specified by the matcher. The matcher is the first argument passed to String#gsub
240 241 242 |
# File 'lib/rake-pipeline/dsl/pipeline_dsl.rb', line 240 def strip(matcher) filter(Rake::Pipeline::GsubFilter, matcher, '') end |