Class: Dredd::Rack::RakeTask

Inherits:
Rake::TaskLib
  • Object
show all
Defined in:
lib/dredd/rack/rake_task.rb

Overview

A clonable Rake task powered by a Dredd::Rack::Runner

Examples:

require 'dredd/rack'
Dredd::Rack::RakeTask.new # run it with `rake dredd`

# Customize the name or description of the Rake task:
namespace :blueprint do
  desc 'Verify an API complies with its blueprint'
  Dredd::Rack::RakeTask.new(:verify)
end
# run it with `rake blueprint:verify`

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args, &task_block) ⇒ RakeTask

Define a task with a custom name, arguments and description



50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/dredd/rack/rake_task.rb', line 50

def initialize(*args, &task_block)
  @name = args.shift || :dredd
  @description = 'Run Dredd::Rack API blueprint verification'
  @runner = Dredd::Rack::Runner.new(ENV['API_HOST'])

  desc description unless ::Rake.application.last_description
  rake_task = task name, *args do |task_args|
    task_block.call(*[self, task_args].slice(0, task_block.arity)) if task_block
    run_task(runner)
  end

  integrate_with_rails!(rake_task)
end

Instance Attribute Details

#descriptionObject (readonly)

Return the task’s description



44
45
46
# File 'lib/dredd/rack/rake_task.rb', line 44

def description
  @description
end

#nameObject (readonly)

Return the task’s name



41
42
43
# File 'lib/dredd/rack/rake_task.rb', line 41

def name
  @name
end

#runnerObject (readonly)

Return the Dredd::Rack::Runner instance



47
48
49
# File 'lib/dredd/rack/rake_task.rb', line 47

def runner
  @runner
end