Module: Thor::Base
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.
15 16 17 |
# File 'lib/thor/base.rb', line 15 def @options end |
Class Method Details
.included(base) ⇒ Object
:nodoc:
52 53 54 55 56 |
# File 'lib/thor/base.rb', line 52 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. Also invoke the source_root if the klass respond to it. This is needed to ensure that the source_root does not change after FileUtils#cd is called.
82 83 84 85 86 87 88 89 90 |
# File 'lib/thor/base.rb', line 82 def register_klass_file(klass) #:nodoc: file = caller[1].match(/(.*):\d+/)[1] klass.source_root if klass.respond_to?(:source_root) 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. Default to color one.
7 8 9 |
# File 'lib/thor/shell.rb', line 7 def self.shell @shell ||= Thor::Shell::Color end |
.shell=(klass) ⇒ Object
Sets the shell used in all Thor classes.
13 14 15 |
# File 'lib/thor/shell.rb', line 13 def self.shell=(klass) @shell = klass end |
.subclass_files ⇒ Object
Returns the files where the subclasses are kept.
Returns
Hash[path<String> => Class]
72 73 74 |
# File 'lib/thor/base.rb', line 72 def subclass_files @subclass_files ||= Hash.new{ |h,k| h[k] = [] } end |
.subclasses ⇒ Object
63 64 65 |
# File 'lib/thor/base.rb', line 63 def subclasses @subclasses ||= [] 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.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/thor/base.rb', line 33 def initialize(args=[], ={}, config={}) Thor::Arguments.parse(self.class.arguments, args).each do |key, value| send("#{key}=", value) end = self.class. = if .is_a?(Array) = config.delete(:task_options) # hook for start = .merge() if Thor::Options.parse(, ) else Thor::Options.parse(, []).merge() end self. = Thor::CoreExt::HashWithIndifferentAccess.new().freeze end |