模块 Bundler::Thor::Base
属性
shell[W]
args[RW]
options[RW]
parent_options[RW]
公共类方法
new(args = [], local_options = {}, config = {}) 点击切换源代码
它接收一个数组形式的参数,以及两个哈希,一个用于选项,另一个用于配置。
请注意,它不检查是否提供了所有必需的参数。这应该由解析器完成。
参数¶ ↑
- args
> -
一个对象数组。这些对象将应用于使用
argument
声明的各自的访问器。 - options<Hash>
-
一个选项哈希,它将作为 self.options 可用。给定的哈希被转换为一个具有不区分大小写的访问、魔术谓词(options.skip?)的哈希,然后被冻结。
- config<Hash>
-
此 Bundler::Thor 类的配置。
# File bundler/vendor/thor/lib/thor/base.rb, line 53 def initialize(args = [], local_options = {}, config = {}) parse_options = self.class.class_options # 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. command_options = config.delete(:command_options) # hook for start parse_options = parse_options.merge(command_options) if command_options if local_options.is_a?(Array) array_options = local_options hash_options = {} else # Handle the case where the class was explicitly instantiated # with pre-parsed options. array_options = [] hash_options = local_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. current_command = config[:current_command] stop_on_unknown = self.class.stop_on_unknown_option? current_command # Give a relation of options. # After parsing, Bundler::Thor::Options check whether right relations are kept relations = if current_command.nil? {exclusive_option_names: [], at_least_one_option_names: []} else current_command.options_relation end self.class.class_exclusive_option_names.map { |n| relations[:exclusive_option_names] << n } self.class.class_at_least_one_option_names.map { |n| relations[:at_least_one_option_names] << n } disable_required_check = self.class.disable_required_check? current_command opts = Bundler::Thor::Options.new(parse_options, hash_options, stop_on_unknown, disable_required_check, relations) self.options = opts.parse(array_options) self.options = config[:class_options].merge(options) 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.check_unknown_options?(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
shell() 点击切换源代码
返回所有 Bundler::Thor 类中使用的 shell。如果您在 Unix 平台上,它将使用彩色日志,否则它将使用没有颜色的基本日志。
# File 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
subclass_files() 点击切换源代码
返回保存子类的文件。
返回¶ ↑
Hash[路径<String> => 类]
# File bundler/vendor/thor/lib/thor/base.rb, line 137 def subclass_files @subclass_files ||= Hash.new { |h, k| h[k] = [] } end
subclasses() 点击切换源代码
返回继承自 Bundler::Thor 或 Bundler::Thor::Group
的类。
返回¶ ↑
# File bundler/vendor/thor/lib/thor/base.rb, line 128 def subclasses @subclasses ||= [] end