Class: Rake::Pipeline::DSL

Inherits:
Object
  • Object
show all
Defined in:
lib/rake-pipeline/dsl.rb

Overview

This class exists purely to provide a convenient DSL for configuring a pipeline.

All instance methods of DSL are available in the context the block passed to Rake::Pipeline.build.

When configuring a pipeline, you must provide both a root, and a series of files using #input.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pipeline) ⇒ void

Create a new Rake::Pipeline::DSL to configure a pipeline.



35
36
37
# File 'lib/rake-pipeline/dsl.rb', line 35

def initialize(pipeline)
  @pipeline = pipeline
end

Instance Attribute Details

#pipelinePipeline (readonly)



13
14
15
# File 'lib/rake-pipeline/dsl.rb', line 13

def pipeline
  @pipeline
end

Class Method Details

.evaluate(pipeline, &block) ⇒ void

This method returns an undefined value.

Configure a pipeline with a passed in block.



23
24
25
26
27
28
# File 'lib/rake-pipeline/dsl.rb', line 23

def self.evaluate(pipeline, &block)
  new(pipeline).instance_eval(&block)
  copy_filter = Rake::Pipeline::ConcatFilter.new
  copy_filter.output_name_generator = proc { |input| input }
  pipeline.add_filter(copy_filter)
end

Instance Method Details

#filter(filter_class, string = nil, &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.

You can also specify a String, which will map all input files into the same output file. This is useful when you want to concatenate a list of files together.



81
82
83
84
85
86
87
88
89
90
91
# File 'lib/rake-pipeline/dsl.rb', line 81

def filter(filter_class, string=nil, &block)
  block ||= if string
    proc { string }
  else
    proc { |input| input }
  end

  filter = filter_class.new
  filter.output_name_generator = block
  pipeline.add_filter(filter)
end

#input(root, glob = "**/*") ⇒ void

This method returns an undefined value.

Define the input location and files for the pipeline.

Examples:

Rake::Pipeline.build do
  input "app/assets", "**/*.js"
  # ...
end


54
55
56
57
# File 'lib/rake-pipeline/dsl.rb', line 54

def input(root, glob="**/*")
  pipeline.input_root = root
  pipeline.input_glob = 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.

Examples:

Pipeline.build do
  input "app/assets"
  output "public"

  # compile coffee files into JS files
  match "*.coffee" do
    filter CompileCoffee do |input|
      input.sub(/coffee$/, "js")
    end
  end

  # because the previous step converted coffeee
  # into JS, the coffee files will be included here
  match "*.js" do
    filter MinifyFilter
    filter Rake::Pipeline::ConcatFilter, "application.js"
  end
end


124
125
126
127
128
129
# File 'lib/rake-pipeline/dsl.rb', line 124

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.



135
136
137
# File 'lib/rake-pipeline/dsl.rb', line 135

def output(root)
  pipeline.output_root = root
end

#tmpdir(root) ⇒ void

This method returns an undefined value.

Specify the location of the temporary directory. Filters will store intermediate build artifacts here.

This defaults "tmp" in the current working directory.



147
148
149
# File 'lib/rake-pipeline/dsl.rb', line 147

def tmpdir(root)
  pipeline.tmpdir = root
end