Module Thor::Util
In: lib/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")

Methods

External Aliases

find_class_and_command_by_namespace -> find_class_and_task_by_namespace

Public Class methods

Receives a string and convert it to camel case. camel_case returns CamelCase.

Parameters

String

Returns

String

Returns a string that has had any glob characters escaped. The glob characters are `* ? { } [ ]`.

Examples

  Thor::Util.escape_globs('[apps]')   # => '\[apps\]'

Parameters

String

Returns

String

Receives a namespace and search for it in the Thor::Base subclasses.

Parameters

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.

Examples

  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 command
  Thor::Util.namespace_to_thor_class("baz:foo")     #=> Baz::Foo, nil
  Thor::Util.namespace_to_thor_class("foo:bar:baz") #=> Foo::Bar, "baz"

Parameters

namespace<String>

Where to look for Thor files.

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 commands can be added to a sandbox, this method is also responsible 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.

Parameters

constant<Object>:The constant to be converted to the thor path.

Returns

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.

Parameters

contents<String>

Returns

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.

Parameters

String

Returns

String

Returns the thor classes declared inside the given class.

Returns the root where thor files are located, depending on the OS.

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.

[Validate]