lotus/utils — pull request #42 by jodosha (2014-11-14 14:10:58+00:00)
Title: Simplify Utils::Class.load!, by extracting .load_from_pattern!

This proposal decouples the semantic for `Lotus::Utils::Class.load!`.

Until now it accepted names as strings to load the corresponding class, and also a special pattern that allowed to lookup for multiple classes.

`Utils::Class.load!` is used a lot by Lotus internals, this decoupling wants to speed up all the cases where the exact match is enough to lookup for a constant.

There are still some cases where the pattern support is needed and we're happy to pay a little perf taxes in order to keep flexible the internals of the framework.

This introduces a new method called `.load_from_pattern!` where we support pattern syntax.
Until the `0.4.0` release `.load!` will still support the pattern case, but it will print a deprecation warning.

### Before

```
require 'lotus/utils/class'

module App
class Hello
end

class HelloWorld
end
end

Lotus::Utils::Class.load!('App::HelloWorld') # => App::HelloWorld
Lotus::Utils::Class.load!('HelloWorld', App) # => App::HelloWorld

Lotus::Utils::Class.load!('App::(Hello|HelloWorld)') # => App::Hello
Lotus::Utils::Class.load!('(Hello|HelloWorld)', App) # => App::Hello
```

### After

```
require 'lotus/utils/class'

module App
class Hello
end

class HelloWorld
end
end

Lotus::Utils::Class.load!('App::HelloWorld') # => App::HelloWorld
Lotus::Utils::Class.load!('HelloWorld', App) # => App::HelloWorld

Lotus::Utils::Class.load_from_pattern!('App::(Hello|HelloWorld)') # => App::Hello
Lotus::Utils::Class.load_from_pattern!('(Hello|HelloWorld)', App) # => App::Hello

# DEPRECATED
Lotus::Utils::Class.load!('App::(Hello|HelloWorld)') # => App::Hello (prints a deprecation warning)
Lotus::Utils::Class.load!('(Hello|HelloWorld)', App) # => App::Hello (prints a deprecation warning)

```