Class: Sake::Task
- Inherits:
-
Object
- Object
- Sake::Task
- Defined in:
- lib/sake.rb
Overview
This is Sake’s version of a Rake task. Please handle with care.
Instance Attribute Summary collapse
-
#comment ⇒ Object
readonly
Returns the value of attribute comment.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
String-ish duck typing, sorting based on Task names.
-
#initialize(name, args = nil, deps = nil, comment = nil, &block) ⇒ Task
constructor
A new instance of Task.
-
#inspect ⇒ Object
Basically to_s.inspect.
-
#to_ruby ⇒ Object
Turn ourselves back into Rake task plaintext.
-
#to_s ⇒ Object
The task name.
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
#comment ⇒ Object (readonly)
Returns the value of attribute comment.
424 425 426 |
# File 'lib/sake.rb', line 424 def comment @comment end |
#name ⇒ Object (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 |
#inspect ⇒ Object
Basically to_s.inspect
475 |
# File 'lib/sake.rb', line 475 def inspect; @name.inspect end |
#to_ruby ⇒ Object
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_s ⇒ Object
The task name
471 |
# File 'lib/sake.rb', line 471 def to_s; @name end |