Module: RakeCommander::Options::Result::ClassMethods

Defined in:
lib/rake-commander/options/result.rb

Instance Method Summary collapse

Instance Method Details

#install_task(&task_method) ⇒ Object

TODO:

think if it should rather raise an ArgumentError when the task was not defined in an instance object of his class.

Note:
  1. This allows stop before invoking the task, may there be options that have this effect (i.e. -h)
  2. We use task_context to open up extensibility.

Extend method to ensure options are parsed before calling task. This only happens if task_method has it's context (binding) with an instance object of this class.



49
50
51
# File 'lib/rake-commander/options/result.rb', line 49

def install_task(&task_method)
  super(&task_context(&task_method))
end

#options_with_defaults(value = nil) ⇒ Boolean

Configuration Setting.

Returns:

  • (Boolean)

    whether results should include options defined with a default, regarless if they are invoked



16
17
18
19
20
21
22
# File 'lib/rake-commander/options/result.rb', line 16

def options_with_defaults(value = nil)
  if value.nil?
    @options_with_defaults || false
  else
    @options_with_defaults = !!value
  end
end

#parse_options(argv = ARGV, results: {}, leftovers: []) {|value, default, short, name, option| ... } ⇒ Object

Note:

this extends the method parameters and changes the returned value.

It re-opens the method and adds a middleware to gather and return the results of the parsing (including the leftovers)

Parameters:

  • leftovers (Array<String>) (defaults to: [])

    see RakeCommander::Options#parse_options`

  • results (Hash) (defaults to: {})

    with short option as key and final value as value.

Yields:

  • (value, default, short, name, option)

    do somethin with parsed value for option

Yield Parameters:

  • value

    [] the resulting parsed value

  • default

    [] the default value of the option

  • short (Symbol)

    the symbol short of the option

  • name (Symbol)

    the symbol name of the option

  • option (RakeCommander::Option)

    the option that is being parsed

See Also:

  • RakeCommander::Options::Result::ClassMethods.`RakeCommander`RakeCommander::Options`RakeCommander::Options#parse_options`


36
37
38
# File 'lib/rake-commander/options/result.rb', line 36

def parse_options(argv = ARGV, results: {}, leftovers: [], &middleware)
  leftovers.push(*super(argv, &results_collector(results, &middleware)))
end