class BradyW::BaseTask

Used to abstract some of the functionality of building custom tasks in Rake out and also provide a convenient point to mock them for testing purposes

Attributes

name[RW]
unless[RW]

Public Class Methods

new(parameters = :task) { |self| ... } click to toggle source
   # File lib/basetask.rb
23 def initialize(parameters = :task)
24   parseParams parameters
25   yield self if block_given?
26   task @name => @dependencies if @dependencies unless @unless
27   define
28 end

Protected Class Methods

validate(value, name, allowed) click to toggle source

Validates whether value is in the allowed list and raises an exception, using name as documentation, if it does not

   # File lib/basetask.rb
15 def self.validate(value, name, allowed)
16   if !allowed.include? value
17     symbols = allowed.collect { |sym| ":#{sym}" }
18     formatted = symbols.join(", ")
19     raise "Invalid #{name} value!  Allowed values: #{formatted}"
20   end
21 end

Protected Instance Methods

shell(*cmd, &block) click to toggle source

Setup here for mocking purposes and also to stop verbose messages from ending up in stderr and causing CruiseControl.net to display errors

   # File lib/basetask.rb
32 def shell(*cmd, &block)
33   options = (Hash === cmd.last) ? cmd.pop : {}
34   options[:verbose] = false
35   command = cmd.first
36   puts "Running #{command} via Rake sh"
37   sh command, options, &block
38 end

Private Instance Methods

define() click to toggle source

Create the tasks defined by this task lib.

   # File lib/basetask.rb
54 def define
55   task name do
56     if not @unless
57       log "Running task: #{@name}"
58       exectask
59     else
60       log "Skipping task: #{@name} due to unless condition specified in rakefile"
61     end
62   end
63   self
64 end
log(text) click to toggle source
   # File lib/basetask.rb
66 def log text
67   puts text
68 end
parseParams(parameters) click to toggle source
   # File lib/basetask.rb
42 def parseParams parameters
43   @name = case parameters
44             when Hash
45               n = parameters.keys[0]
46               @dependencies = parameters[n]
47               n
48             else
49               parameters
50           end
51 end