Method: Bundler::Thor::Base#initialize
- Defined in:
- lib/bundler/vendor/thor/lib/thor/base.rb
#initialize(args = [], local_options = {}, config = {}) ⇒ Object
It receives arguments in an Array and two hashes, one for options and other for configuration.
Notice that it does not check if all required arguments were supplied. It should be done by the parser.
Parameters
- args<Array>
-
An array of objects. The objects are applied to their respective accessors declared with
argument. - options<Hash>
-
An options hash that will be available as self.options. The hash given is converted to a hash with indifferent access, magic predicates (options.skip?) and then frozen.
- config<Hash>
-
Configuration for this Bundler::Thor class.
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 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/bundler/vendor/thor/lib/thor/base.rb', line 53 def initialize(args = [], = {}, config = {}) = self.class. # The start method splits inbound arguments at the first argument # that looks like an option (starts with - or --). It then calls # new, passing in the two halves of the arguments Array as the # first two parameters. = config.delete(:command_options) # hook for start = .merge() if if .is_a?(Array) = = {} else # Handle the case where the class was explicitly instantiated # with pre-parsed options. = [] = end # Let Bundler::Thor::Options parse the options first, so it can remove # declared options from the array. This will leave us with # a list of arguments that weren't declared. stop_on_unknown = self.class.stop_on_unknown_option? config[:current_command] disable_required_check = self.class.disable_required_check? config[:current_command] opts = Bundler::Thor::Options.new(, , stop_on_unknown, disable_required_check) self. = opts.parse() self. = config[:class_options].merge() if config[:class_options] # If unknown options are disallowed, make sure that none of the # remaining arguments looks like an option. opts.check_unknown! if self.class.(config) # Add the remaining arguments from the options parser to the # arguments passed in to initialize. Then remove any positional # arguments declared using #argument (this is primarily used # by Bundler::Thor::Group). Tis will leave us with the remaining # positional arguments. to_parse = args to_parse += opts.remaining unless self.class.strict_args_position?(config) thor_args = Bundler::Thor::Arguments.new(self.class.arguments) thor_args.parse(to_parse).each { |k, v| __send__("#{k}=", v) } @args = thor_args.remaining end |