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.

Parameters:

  • pipeline (Pipeline)

    the pipeline that the DSL should configure.



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

def initialize(pipeline)
  @pipeline = pipeline
end

Instance Attribute Details

#pipelinePipeline (readonly)

Returns the pipeline the DSL should configure.

Returns:

  • (Pipeline)

    the pipeline the DSL should configure



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.

Parameters:

  • pipeline (Pipeline)

    the pipeline that the DSL should configure.

  • block (Proc)

    the block describing the configuration. This block will be evaluated in the context of a new instance of Rake::Pipeline::DSL



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, *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.

Parameters:

  • filter_class (Class)

    the class of the filter.

  • ctor_args (Array)

    a list of arguments to pass to the filter’s constructor.

  • block (Proc)

    an output file name generator.

See Also:



80
81
82
83
# File 'lib/rake-pipeline/dsl.rb', line 80

def filter(filter_class, *ctor_args, &block)
  filter = filter_class.new(*ctor_args, &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

Parameters:

  • root (String)

    the root path where the pipeline should find its input files.

  • glob (String) (defaults to: "**/*")

    a file pattern that represents the list of all files that the pipeline should process. The default is */.



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

Parameters:

  • pattern (String)

    a glob pattern to match

  • block (Proc)

    a block that supplies filters

Returns:



116
117
118
119
120
121
# File 'lib/rake-pipeline/dsl.rb', line 116

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.

Parameters:

  • root (String)

    the output directory.



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

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.

Parameters:

  • root (String)

    the temporary directory



139
140
141
# File 'lib/rake-pipeline/dsl.rb', line 139

def tmpdir(root)
  pipeline.tmpdir = root
end