Class: Sake::Task

Inherits:
Object
  • Object
show all
Defined in:
lib/sake.rb

Overview

This is Sake’s version of a Rake task. Please handle with care.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, deps = nil, comment = nil, &block) ⇒ Task

Returns a new instance of Task.



407
408
409
410
411
412
# File 'lib/sake.rb', line 407

def initialize(name, deps = nil, comment = nil, &block)
  @name    = name
  @comment = comment
  @deps    = Array(deps)
  @body    = block
end

Instance Attribute Details

#commentObject (readonly)

Returns the value of attribute comment.



405
406
407
# File 'lib/sake.rb', line 405

def comment
  @comment
end

#nameObject (readonly)

Returns the value of attribute name.



405
406
407
# File 'lib/sake.rb', line 405

def name
  @name
end

Instance Method Details

#<=>(other) ⇒ Object

String-ish duck typing



436
437
438
# File 'lib/sake.rb', line 436

def <=>(other)
  to_s <=> other.to_s
end

#inspectObject



441
# File 'lib/sake.rb', line 441

def inspect; @name.inspect end

#to_rubyObject

Turn ourselves back into Rake task plaintext.



416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
# File 'lib/sake.rb', line 416

def to_ruby
  out = ''
  out << "desc '#{@comment.gsub("'", "\\\\'")}'\n" if @comment
  out << "task '#{@name}'"

  if @deps.any?
    deps = @deps.map { |dep| "'#{dep}'" }.join(', ')
    out << " => [ #{deps} ]" 
  end

  out << " do\n"
  
  # get rid of the proc { / } lines
  out << @body.to_ruby.split("\n")[1...-1].join("\n") rescue nil

  out << "\nend\n"
end

#to_sObject



440
# File 'lib/sake.rb', line 440

def to_s; @name end