Class: Rake::Task

Inherits:
Object
  • Object
show all
Defined in:
lib/rake/leaves.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#request_missing_params=(value) ⇒ Object (writeonly)

Sets the attribute request_missing_params

Parameters:

  • value

    the value to set the attribute request_missing_params to.



37
38
39
# File 'lib/rake/leaves.rb', line 37

def request_missing_params=(value)
  @request_missing_params = value
end

Instance Method Details

#add_optional_param(name, default = nil) ⇒ Object

Add an optional argument to the task (along with an optional default)



88
89
90
# 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) ⇒ Object

Alias a task argument (same usage as alias_method)



93
94
95
96
# 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) ⇒ Object

Add a required argument to the task



83
84
85
# File 'lib/rake/leaves.rb', line 83

def add_required_param (name)
  required_params[name.to_sym] = nil
end

#argsObject

Gathers and returns all args for the task. Missing required args are requested via standard in



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# 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) ⇒ Object

Call self.args in self.invoke_with_call_chain so that all the arg checking is done before any tasks are executed



43
44
45
46
# File 'lib/rake/leaves.rb', line 43

def invoke_with_call_chain (*args)
  self.args
  original_invoke_with_call_chain *args
end

#original_invoke_with_call_chainObject



39
# File 'lib/rake/leaves.rb', line 39

alias_method :original_invoke_with_call_chain, :invoke_with_call_chain