Class: Cape::Rake
- Inherits:
-
Object
- Object
- Cape::Rake
- Defined in:
- lib/cape/rake.rb
Overview
An abstraction of the Rake installation and available tasks.
Constant Summary collapse
- DEFAULT_EXECUTABLE =
The default command used to run Rake. We use ‘bundle check` to detect the presence of Bundler and a Bundler configuration. If Bundler is installed on the computer and configured, we prepend `rake` with `bundle exec`.
( '/usr/bin/env ' + '`' + '/usr/bin/env bundle check >/dev/null 2>&1; ' + 'case $? in ' + # Exit code 0: bundle is defined and installed # Exit code 1: bundle is defined but not installed '0|1 ) ' + 'echo bundle exec ' + ';; ' + 'esac' + '` ' + 'rake' ).freeze
Instance Attribute Summary collapse
-
#remote_executable ⇒ String
The command used to run Rake on remote computers.
Instance Method Summary collapse
-
#==(other) ⇒ true, false
Compares the Rake object to another.
-
#each_task(task_expression = nil) {|task| ... } ⇒ Rake
Enumerates Rake tasks.
-
#expire_cache! ⇒ Object
Forces cached Rake task metadata (if any) to be discarded.
-
#initialize(attributes = {}) ⇒ Rake
constructor
Constructs a new Rake object with the specified attributes.
-
#local_executable ⇒ String
The command used to run Rake on the local computer.
-
#local_executable=(value) ⇒ String
Sets the command used to run Rake on the local computer and discards any cached Rake task metadata.
Constructor Details
#initialize(attributes = {}) ⇒ Rake
Constructs a new Rake object with the specified attributes.
34 35 36 37 38 |
# File 'lib/cape/rake.rb', line 34 def initialize(attributes={}) attributes.each do |name, value| send "#{name}=", value end end |
Instance Attribute Details
#remote_executable ⇒ String
The command used to run Rake on remote computers.
125 126 127 |
# File 'lib/cape/rake.rb', line 125 def remote_executable @remote_executable ||= DEFAULT_EXECUTABLE end |
Instance Method Details
#==(other) ⇒ true, false
Compares the Rake object to another.
46 47 48 49 50 |
# File 'lib/cape/rake.rb', line 46 def ==(other) other.kind_of?(Rake) && (other.local_executable == local_executable) && (other.remote_executable == remote_executable) end |
#each_task(task_expression = nil) {|task| ... } ⇒ Rake
Enumerates Rake tasks.
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/cape/rake.rb', line 61 def each_task(task_expression=nil) previous_task, this_task = nil, nil task_expression = task_expression ? ::Regexp.escape(task_expression.to_s) : '.+?' regexp = /^rake (#{task_expression}(?::.+?)?)(?:\[(.+?)\])?\s+#\s*(.*)/ each_output_line do |l| unless (matches = l.chomp.match(regexp)) next end previous_task = this_task this_task = {}.tap do |t| t[:name] = matches[1].strip t[:parameters] = matches[2].split(',') if matches[2] t[:description] = matches[3] end if previous_task all_but_last_segment = this_task[:name].split(':')[0...-1].join(':') previous_task[:default] = all_but_last_segment == previous_task[:name] yield previous_task end end yield this_task if this_task self end |
#expire_cache! ⇒ Object
Forces cached Rake task metadata (if any) to be discarded.
90 91 92 93 |
# File 'lib/cape/rake.rb', line 90 def expire_cache! @output_lines = nil self end |
#local_executable ⇒ String
The command used to run Rake on the local computer.
100 101 102 |
# File 'lib/cape/rake.rb', line 100 def local_executable @local_executable ||= DEFAULT_EXECUTABLE end |
#local_executable=(value) ⇒ String
Sets the command used to run Rake on the local computer and discards any cached Rake task metadata.
112 113 114 115 116 117 118 |
# File 'lib/cape/rake.rb', line 112 def local_executable=(value) unless @local_executable == value @local_executable = value expire_cache! end value end |