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, args = nil, deps = nil, comment = nil, &block) ⇒ Task

Returns a new instance of Task.



426
427
428
429
430
431
432
# File 'lib/sake.rb', line 426

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

Instance Attribute Details

#commentObject (readonly)

Returns the value of attribute comment.



424
425
426
# File 'lib/sake.rb', line 424

def comment
  @comment
end

#nameObject (readonly)

Returns the value of attribute name.



424
425
426
# File 'lib/sake.rb', line 424

def name
  @name
end

Instance Method Details

#<=>(other) ⇒ Object

String-ish duck typing, sorting based on Task names



465
466
467
# File 'lib/sake.rb', line 465

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

#inspectObject

Basically to_s.inspect



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

def inspect; @name.inspect end

#to_rubyObject

Turn ourselves back into Rake task plaintext.



436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
# File 'lib/sake.rb', line 436

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

  if @args.any?
    args = @args.map { |arg| ":#{arg}" }.join(', ')
    out << ", #{args} "
  end

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

  if @args.any?
    out << " do |t, args|\n"
  else
    out << " do\n"
  end
  
  # get rid of the proc { / } lines
  out << @body.to_ruby.split("\n")[1...-1].join("\n") rescue nil

  out << "\nend\n"
end

#to_sObject

The task name



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

def to_s; @name end