lib/lotus/utils/class.rb in lotus-utils-0.5.2 vs lib/lotus/utils/class.rb in lotus-utils-0.6.0
- old
+ new
@@ -1,7 +1,6 @@
require 'lotus/utils/string'
-require 'lotus/utils/deprecation'
module Lotus
module Utils
# Class utilities
# @since 0.1.0
@@ -37,18 +36,11 @@
# Lotus::Utils::Class.load!('Service', App) # => App::Service
#
# # with missing constant
# Lotus::Utils::Class.load!('Unknown') # => raises NameError
def self.load!(name, namespace = Object)
- name = name.to_s
-
- if name.match(/\|/)
- Utils::Deprecation.new("Using Lotus::Utils::Class.load! with a pattern is deprecated, please use Lotus::Utils::Class.load_from_pattern!: #{ name }, #{ namespace }")
- return load_from_pattern!(name, namespace)
- end
-
- namespace.const_get(name)
+ namespace.const_get(name.to_s)
end
# Loads a class from the given pattern name and namespace
#
# @param pattern [String] the class name pattern
@@ -73,20 +65,20 @@
# class ServiceEndpoint
# end
# end
#
# # basic usage
- # Lotus::Utils::Class.load!('App::Service') # => App::Service
+ # Lotus::Utils::Class.load_from_pattern!('App::Service') # => App::Service
#
# # with explicit namespace
- # Lotus::Utils::Class.load!('Service', App) # => App::Service
+ # Lotus::Utils::Class.load_from_pattern!('Service', App) # => App::Service
#
# # with pattern
- # Lotus::Utils::Class.load!('App::Service(::Endpoint|Endpoint)') # => App::Service::Endpoint
- # Lotus::Utils::Class.load!('App::Service(Endpoint|::Endpoint)') # => App::ServiceEndpoint
+ # Lotus::Utils::Class.load_from_pattern!('App::Service(::Endpoint|Endpoint)') # => App::Service::Endpoint
+ # Lotus::Utils::Class.load_from_pattern!('App::Service(Endpoint|::Endpoint)') # => App::ServiceEndpoint
#
# # with missing constant
- # Lotus::Utils::Class.load!('Unknown') # => raises NameError
+ # Lotus::Utils::Class.load_from_pattern!('Unknown') # => raises NameError
def self.load_from_pattern!(pattern, namespace = Object)
String.new(pattern).tokenize do |token|
begin
return namespace.const_get(token)
rescue NameError