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, 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, deps = nil, comment = nil, &block) ⇒ Task
Returns a new instance of Task.
410 411 412 413 414 415 |
# File 'lib/sake.rb', line 410 def initialize(name, deps = nil, comment = nil, &block) @name = name @comment = comment @deps = Array(deps) @body = block end |
Instance Attribute Details
#comment ⇒ Object (readonly)
Returns the value of attribute comment.
408 409 410 |
# File 'lib/sake.rb', line 408 def comment @comment end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
408 409 410 |
# File 'lib/sake.rb', line 408 def name @name end |
Instance Method Details
#<=>(other) ⇒ Object
String-ish duck typing, sorting based on Task names
439 440 441 |
# File 'lib/sake.rb', line 439 def <=>(other) to_s <=> other.to_s end |
#inspect ⇒ Object
Basically to_s.inspect
449 |
# File 'lib/sake.rb', line 449 def inspect; @name.inspect end |
#to_ruby ⇒ Object
Turn ourselves back into Rake task plaintext.
419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 |
# File 'lib/sake.rb', line 419 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_s ⇒ Object
The task name
445 |
# File 'lib/sake.rb', line 445 def to_s; @name end |