# Class: YARD::Rake::YardocTask

Inherits:
  Rake::TaskLib
  - Object
  - Rake::TaskLib
  - YARD::Rake::YardocTask
  show all

Defined in:
  lib/yard/rake/yardoc_task.rb

## Overview

The rake task to run CLI::Yardoc and generate documentation.

## Instance Attribute Summary collapse

- #after ⇒ Proc

  Runs a `Proc` after the task.

- #before ⇒ Proc

  Runs a `Proc` before the task.

- #files ⇒ Array<String>

  The Ruby source files (and any extra documentation files separated by ‘-’) to process.

- #name ⇒ String

  The name of the task.

- #options ⇒ Array<String>

  Options to pass to CLI::Yardoc.

- #stats_options ⇒ Array<String>

  Options to pass to CLI::Stats.

- #verifier ⇒ Verifier, Proc

  An optional Verifier to run against all objects being generated.

## Instance Method Summary collapse

- #define ⇒ void protected

  Defines the rake task.

- #initialize(name = :yard) {|_self| ... } ⇒ YardocTask constructor

  Creates a new task with name `name`.

## Constructor Details

### #initialize(name = :yard) {|_self| ... } ⇒ `YardocTask`

Creates a new task with name `name`.

Parameters:

- name (`String`, `Symbol`) (defaults to: `:yard`) —

  the name of the rake task

Yields:

- a block to allow any options to be modified on the task

Yield Parameters:

- _self (`YardocTask`) —

  the task object to allow any parameters to be changed.

    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62

    # File 'lib/yard/rake/yardoc_task.rb', line 50

    def initialize(name = :yard)
      @name = name
      @options = []
      @stats_options = []
      @files = []

      yield self if block_given?
      self.options += ENV['OPTS'].split(/[ ,]/) if ENV['OPTS']
      self.files   += ENV['FILES'].split(/[ ,]/) if ENV['FILES']
      self.options << '--no-stats' unless stats_options.empty?

      define
    end

## Instance Attribute Details

### #after ⇒ `Proc`

Runs a `Proc` after the task

Returns:

- (`Proc`) —

  a proc to call after running the task

    36
    37
    38

    # File 'lib/yard/rake/yardoc_task.rb', line 36

    def after
      @after
    end

### #before ⇒ `Proc`

Runs a `Proc` before the task

Returns:

- (`Proc`) —

  a proc to call before running the task

    32
    33
    34

    # File 'lib/yard/rake/yardoc_task.rb', line 32

    def before
      @before
    end

### #files ⇒ `Array<String>`

The Ruby source files (and any extra documentation files separated by ‘-’) to process.

#### Examples:

#####

Task files assignment

    YARD::Rake::YardocTask.new do |t|
      t.files   = ['app/**/*.rb', 'lib/**/*.rb', '-', 'doc/FAQ.md', 'doc/Changes.md']
    end

Returns:

- (`Array<String>`) —

  a list of files

    28
    29
    30

    # File 'lib/yard/rake/yardoc_task.rb', line 28

    def files
      @files
    end

### #name ⇒ `String`

The name of the task

Returns:

- (`String`) —

  the task name

    11
    12
    13

    # File 'lib/yard/rake/yardoc_task.rb', line 11

    def name
      @name
    end

### #options ⇒ `Array<String>`

Options to pass to CLI::Yardoc

Returns:

- (`Array<String>`) —

  the options passed to the commandline utility

    15
    16
    17

    # File 'lib/yard/rake/yardoc_task.rb', line 15

    def options
      @options
    end

### #stats_options ⇒ `Array<String>`

Options to pass to CLI::Stats

Returns:

- (`Array<String>`) —

  the options passed to the stats utility

    19
    20
    21

    # File 'lib/yard/rake/yardoc_task.rb', line 19

    def stats_options
      @stats_options
    end

### #verifier ⇒ `Verifier`, `Proc`

Returns an optional Verifier to run against all objects being generated. Any object that the verifier returns false for will be excluded from documentation. This attribute can also be a lambda.

Returns:

- (`Verifier`, `Proc`) —

  an optional Verifier to run against all objects being generated. Any object that the verifier returns false for will be excluded from documentation. This attribute can also be a lambda.

See Also:

- Verifier

    42
    43
    44

    # File 'lib/yard/rake/yardoc_task.rb', line 42

    def verifier
      @verifier
    end

## Instance Method Details

### #define ⇒ `void` (protected)

This method returns an undefined value.

Defines the rake task

    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78

    # File 'lib/yard/rake/yardoc_task.rb', line 68

    def define
      desc "Generate YARD Documentation" unless ::Rake.application.last_description
      task(name) do
        before.call if before.is_a?(Proc)
        yardoc = YARD::CLI::Yardoc.new
        yardoc.options[:verifier] = verifier if verifier
        yardoc.run(*(options + files))
        YARD::CLI::Stats.run(*(stats_options + ['--use-cache'])) unless stats_options.empty?
        after.call if after.is_a?(Proc)
      end
    end