модуль Bundler::Thor::Base
Атрибуты
Публичные методы класса
# File lib/bundler/vendor/thor/lib/thor/base.rb, line 44
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.
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(parse_options, hash_options, stop_on_unknown, disable_required_check)
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 Получает аргументы в виде Array и двух хэшей: один для опций, другой для конфигурации.
Обратите внимание, что не проверяется, были ли переданы все необходимые аргументы. Это должно быть сделано анализатором.
Параметры
- args<Array>
-
Массив объектов. Объекты применяются к соответствующим аксессорам, объявленным с помощью
argument. - options<Hash>
-
Хэш опций, который будет доступен как self.options. Переданный хэш преобразуется в хэш с безразличным доступом, магическими предикатами (options.skip?) и затем замораживается.
- config<Hash>
-
Конфигурация для класса Bundler::Thor.
# 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 Возвращает оболочку, используемую во всех классах Bundler::Thor. В Unix-системах используется цветной лог, в других — базовый, без цвета.
# File lib/bundler/vendor/thor/lib/thor/base.rb, line 111
def subclass_files
@subclass_files ||= Hash.new { |h, k| h[k] = [] }
end Возвращает файлы, где хранятся подклассы.
Возвращает
Хэш [путь<Строка> => Класс]
# File lib/bundler/vendor/thor/lib/thor/base.rb, line 102 def subclasses @subclasses ||= [] end
Возвращает классы, которые наследуются от Bundler::Thor или Bundler::Thor::Group.
Возвращает
Массив
Ruby Core © 1993–2017 Yukihiro Matsumoto
Licensed under the Ruby License.
Ruby Standard Library © contributors
Licensed under their own licenses.