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.
19 20 21 |
# File 'lib/thor/base.rb', line 19 def end |
Class Method Details
.included(base) ⇒ Object
:nodoc:
58 59 60 61 62 |
# File 'lib/thor/base.rb', line 58 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.
85 86 87 88 89 90 91 |
# File 'lib/thor/base.rb', line 85 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. 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
78 79 80 |
# File 'lib/thor/base.rb', line 78 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
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
Configuration for this Thor class.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/thor/base.rb', line 37 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 , = , {} else , = [], end = Thor::Options.parse(, ) self. = Thor::CoreExt::HashWithIndifferentAccess.new().merge!() self..freeze end |