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.
-
#initialize(name, deps = nil, comment = nil, &block) ⇒ Task
constructor
A new instance of Task.
- #inspect ⇒ Object
-
#to_ruby ⇒ Object
Turn ourselves back into Rake task plaintext.
- #to_s ⇒ Object
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
#comment ⇒ Object (readonly)
Returns the value of attribute comment.
405 406 407 |
# File 'lib/sake.rb', line 405 def comment @comment end |
#name ⇒ Object (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 |
#inspect ⇒ Object
441 |
# File 'lib/sake.rb', line 441 def inspect; @name.inspect end |
#to_ruby ⇒ Object
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_s ⇒ Object
440 |
# File 'lib/sake.rb', line 440 def to_s; @name end |