Module | Thor::Util |
In: |
lib/bundler/vendor/thor/util.rb
|
This module holds several utilities:
1) Methods to convert thor namespaces to constants and vice-versa.
Thor::Util.namespace_from_thor_class(Foo::Bar::Baz) #=> "foo:bar:baz"
2) Loading thor files and sandboxing:
Thor::Util.load_thorfile("~/.thor/foo")
Receives a string and convert it to camel case. camel_case returns CamelCase.
String
String
Returns a string that has had any glob characters escaped. The glob characters are `* ? { } [ ]`.
Thor::Util.escape_globs('[apps]') # => '\[apps\]'
String
String
Receives a namespace and search for it in the Thor::Base subclasses.
namespace<String>: | The namespace to search for. |
Receives a namespace and tries to retrieve a Thor or Thor::Group class from it. It first searches for a class using the all the given namespace, if it‘s not found, removes the highest entry and searches for the class again. If found, returns the highest entry as the class name.
class Foo::Bar < Thor def baz end end class Baz::Foo < Thor::Group end Thor::Util.namespace_to_thor_class("foo:bar") #=> Foo::Bar, nil # will invoke default task Thor::Util.namespace_to_thor_class("baz:foo") #=> Baz::Foo, nil Thor::Util.namespace_to_thor_class("foo:bar:baz") #=> Foo::Bar, "baz"
namespace<String>
Receives a path and load the thor file in the path. The file is evaluated inside the sandbox to avoid namespacing conflicts.
Receives a constant and converts it to a Thor namespace. Since Thor tasks can be added to a sandbox, this method is also responsable for removing the sandbox namespace.
This method should not be used in general because it‘s used to deal with older versions of Thor. On current versions, if you need to get the namespace from a class, just call namespace on it.
constant<Object>: | The constant to be converted to the thor path. |
String: | If we receive Foo::Bar::Baz it returns "foo:bar:baz" |
Given the contents, evaluate it inside the sandbox and returns the namespaces defined in the sandbox.
contents<String>
Array[Object]
Return the path to the ruby interpreter taking into account multiple installations and windows extensions.
Receives a string and convert it to snake case. SnakeCase returns snake_case.
String
String
Returns the files in the thor root. On Windows thor_root will be something like this:
C:\Documents and Settings\james\.thor
If we don‘t gsub the \ character, Dir.glob will fail.