Module: Thor::Base
- Defined in:
- lib/bundler/vendor/thor/base.rb,
lib/bundler/vendor/thor/shell.rb
Defined Under Namespace
Modules: ClassMethods
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
Class Method Summary collapse
-
.included(base) ⇒ Object
:nodoc:.
-
.register_klass_file(klass) ⇒ Object
Whenever a class inherits from Thor or Thor::Group, we should track the class and the file on Thor::Base.
-
.shell ⇒ Object
Returns the shell used in all Thor classes.
-
.shell=(klass) ⇒ Object
Sets the shell used in all Thor classes.
-
.subclass_files ⇒ Object
Returns the files where the subclasses are kept.
-
.subclasses ⇒ Object
Returns the classes that inherits from Thor or Thor::Group.
Instance Method Summary collapse
-
#initialize(args = [], options = {}, config = {}) ⇒ Object
It receives arguments in an Array and two hashes, one for options and other for configuration.
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
22 23 24 |
# File 'lib/bundler/vendor/thor/base.rb', line 22 def @options end |
Class Method Details
.included(base) ⇒ Object
:nodoc:
60 61 62 63 64 |
# File 'lib/bundler/vendor/thor/base.rb', line 60 def included(base) #:nodoc: base.send :extend, ClassMethods base.send :include, Invocation base.send :include, Shell end |
.register_klass_file(klass) ⇒ Object
Whenever a class inherits from Thor or Thor::Group, we should track the class and the file on Thor::Base. This is the method responsable for it.
87 88 89 90 91 92 93 |
# File 'lib/bundler/vendor/thor/base.rb', line 87 def register_klass_file(klass) #:nodoc: file = caller[1].match(/(.*):\d+/)[1] Thor::Base.subclasses << klass unless Thor::Base.subclasses.include?(klass) file_subclasses = Thor::Base.subclass_files[File.(file)] file_subclasses << klass unless file_subclasses.include?(klass) end |
.shell ⇒ Object
Returns the shell used in all Thor classes. If you are in a Unix platform it will use a colored log, otherwise it will use a basic one without color.
8 9 10 11 12 13 14 15 16 |
# File 'lib/bundler/vendor/thor/shell.rb', line 8 def self.shell @shell ||= if ENV['THOR_SHELL'] && ENV['THOR_SHELL'].size > 0 Thor::Shell.const_get(ENV['THOR_SHELL']) elsif RbConfig::CONFIG['host_os'] =~ /mswin|mingw/ Thor::Shell::Basic else Thor::Shell::Color end end |
.shell=(klass) ⇒ Object
Sets the shell used in all Thor classes.
20 21 22 |
# File 'lib/bundler/vendor/thor/shell.rb', line 20 def self.shell=(klass) @shell = klass end |
.subclass_files ⇒ Object
Returns the files where the subclasses are kept.
Returns
Hash[path<String> => Class]
80 81 82 |
# File 'lib/bundler/vendor/thor/base.rb', line 80 def subclass_files @subclass_files ||= Hash.new{ |h,k| h[k] = [] } end |
Instance Method Details
#initialize(args = [], 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 Thor class.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/bundler/vendor/thor/base.rb', line 40 def initialize(args=[], ={}, config={}) args = Thor::Arguments.parse(self.class.arguments, args) args.each { |key, value| send("#{key}=", value) } = self.class. if .is_a?(Array) = config.delete(:task_options) # hook for start = .merge() if , = , {} else , = [], end opts = Thor::Options.new(, ) self. = opts.parse() opts.check_unknown! if self.class.(config) end |