Class: Rake::Pipeline::DSL::PipelineDSL

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pipeline) ⇒ void

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

Parameters:

  • pipeline (Pipeline)

    the pipeline that the PipelineDSL should configure.



53
54
55
# File 'lib/rake-pipeline/dsl/pipeline_dsl.rb', line 53

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



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.

Parameters:

  • pipeline (Pipeline)

    the pipeline that the PipelineDSL 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::PipelineDSL



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, options, &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 = options[: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 = options[: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.



157
158
159
160
161
162
163
# File 'lib/rake-pipeline/dsl/pipeline_dsl.rb', line 157

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.

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:



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

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

This method returns an undefined value.

Add an input location and files to a pipeline.

Examples:

Rake::Pipeline::Project.build do
  input "app" do
    input "assets", "**/*.js"
    # ...
  end
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 files that the pipeline should process within root. The default is */.



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.

Examples:

Rake::Pipeline::Project.build do
  output "public"

  input "app/assets" do
    # compile coffee files into JS files
    match "*.coffee" do
      coffee_script
    end

    # because the previous step converted coffeee
    # into JS, the coffee files will be included here
    match "*.js" do
      uglify
      concat "application.js"
    end
  end
end

Parameters:

  • pattern (String)

    a glob pattern to match

  • block (Proc)

    a block that supplies filters

Returns:



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.

Parameters:

  • root (String)

    the output directory.



145
146
147
# File 'lib/rake-pipeline/dsl/pipeline_dsl.rb', line 145

def output(root)
  pipeline.output_root = root
end