Module: Bundler::Thor::Base
Relationships & Source Files | |
Namespace Children | |
Modules:
| |
Extension / Inclusion / Inheritance Descendants | |
Included In:
| |
Defined in: | lib/bundler/vendor/thor/lib/thor/base.rb, lib/bundler/vendor/thor/lib/thor/shell.rb |
Class Attribute Summary
-
.shell
rw
Returns the shell used in all
::Bundler::Thor
classes. - .shell=(value) rw
Class Method Summary
-
.subclass_files
Returns the files where the subclasses are kept.
-
.subclasses
Returns the classes that inherits from
::Bundler::Thor
orGroup
. - .included(base) Internal use only
-
.register_klass_file(klass)
Internal use only
Whenever a class inherits from
::Bundler::Thor
orGroup
, we should track the class and the file onBase
.
Instance Attribute Summary
- #args rw
- #options rw
- #parent_options rw
Instance Method Summary
-
#initialize(args = [], local_options = {}, config = {})
It receives arguments in an Array and two hashes, one for options and other for configuration.
Class Attribute Details
.shell (rw)
Returns the shell used in all ::Bundler::Thor
classes. If you are in a Unix platform it will use a colored log, otherwise it will use a basic one without color.
# File 'lib/bundler/vendor/thor/lib/thor/shell.rb', line 11
def shell @shell ||= if ENV["THOR_SHELL"] && !ENV["THOR_SHELL"].empty? Bundler::Thor::Shell.const_get(ENV["THOR_SHELL"]) elsif RbConfig::CONFIG["host_os"] =~ /mswin|mingw/ && !ENV["ANSICON"] Bundler::Thor::Shell::Basic else Bundler::Thor::Shell::Color end end
.shell=(value) (rw)
[ GitHub ]# File 'lib/bundler/vendor/thor/lib/thor/shell.rb', line 6
attr_writer :shell
Class Method Details
.included(base)
# File 'lib/bundler/vendor/thor/lib/thor/base.rb', line 100
def included(base) #:nodoc: super(base) base.extend ClassMethods base.send :include, Invocation base.send :include, Shell end
.register_klass_file(klass)
Whenever a class inherits from ::Bundler::Thor
or Group
, we should track the class and the file on Base
. This is the method responsible for it.
# File 'lib/bundler/vendor/thor/lib/thor/base.rb', line 128
def register_klass_file(klass) #:nodoc: file = caller[1].match(/(.*):\d+/)[1] Bundler::Thor::Base.subclasses << klass unless Bundler::Thor::Base.subclasses.include?(klass) file_subclasses = Bundler::Thor::Base.subclass_files[File. (file)] file_subclasses << klass unless file_subclasses.include?(klass) end
.subclass_files
Returns the files where the subclasses are kept.
Returns
Hash[path<String> => Class]
# File 'lib/bundler/vendor/thor/lib/thor/base.rb', line 121
def subclass_files @subclass_files ||= Hash.new { |h, k| h[k] = [] } end
.subclasses
# File 'lib/bundler/vendor/thor/lib/thor/base.rb', line 112
def subclasses @subclasses ||= [] end
Instance Attribute Details
#args (rw)
[ GitHub ]# File 'lib/bundler/vendor/thor/lib/thor/base.rb', line 35
attr_accessor :, :, :args
#options (rw)
[ GitHub ]# File 'lib/bundler/vendor/thor/lib/thor/base.rb', line 35
attr_accessor :, :, :args
#parent_options (rw)
[ GitHub ]# File 'lib/bundler/vendor/thor/lib/thor/base.rb', line 35
attr_accessor :, :, :args
Instance Method Details
#initialize(args = [], local_options = {}, config = {})
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.
# 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(: ) # 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[: ].merge( ) if config[: ] # 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