class Rake::Task
Attributes
request_missing_params[W]
Public Instance Methods
add_optional_param(name, default = nil)
click to toggle source
Add an optional argument to the task (along with an optional default)
# File lib/rake/leaves.rb, line 88 def add_optional_param (name, default = nil) optional_params[name.to_sym] = default end
add_param_alias(new_name, original_name)
click to toggle source
Alias a task argument (same usage as alias_method)
# File lib/rake/leaves.rb, line 93 def add_param_alias (new_name, original_name) param_aliases[original_name.to_sym] ||= [] param_aliases[original_name.to_sym].push new_name.to_sym end
add_required_param(name)
click to toggle source
Add a required argument to the task
# File lib/rake/leaves.rb, line 83 def add_required_param (name) required_params[name.to_sym] = nil end
args()
click to toggle source
Gathers and returns all args for the task. Missing required args are requested via standard in
# File lib/rake/leaves.rb, line 50 def args unless @args errors = [] @args = required_params .merge(optional_params) .inject({}) do |args, (name, default)| # Check for a value supplied under an alias param_aliases[name].reverse.each { |alias_name| args[name] ||= ENV[alias_name.to_s] } if param_aliases[name] # Set the arg to user input or its default value args[name] ||= ENV[name.to_s] || default # If an argument is a) missing and b) required, then # request it or generate an error message if args[name].nil? && required_params.keys.include?(name) if @request_missing_params args[name] = request_argument name else errors.push "Missing argument '#{name}'" end end args end abort errors.join "\n" unless errors.empty? end @args end
invoke_with_call_chain(*args)
click to toggle source
Call self.args in self.invoke_with_call_chain so that all the arg checking is done before any tasks are executed
# File lib/rake/leaves.rb, line 43 def invoke_with_call_chain (*args) self.args original_invoke_with_call_chain *args end
Also aliased as: original_invoke_with_call_chain
Private Instance Methods
optional_params()
click to toggle source
optional_params
getter, cleaner than aliasing initialize to set the default value
# File lib/rake/leaves.rb, line 108 def optional_params @optional_params ||= {} end
param_aliases()
click to toggle source
param_aliases
getter, cleaner than aliasing initialize to set the default value
# File lib/rake/leaves.rb, line 114 def param_aliases @param_aliases ||= {} end
request_argument(name)
click to toggle source
Request an argument from the user via standard in
# File lib/rake/leaves.rb, line 119 def request_argument (name) STDOUT.print "Enter #{name} for #{@name}: " ENV[name.to_s] = STDIN.gets.strip end
required_params()
click to toggle source
required_params
getter, cleaner than aliasing initialize to set the default value
# File lib/rake/leaves.rb, line 102 def required_params @required_params ||= {} end