Class: Hanami::Utils::Class
- Inherits:
-
Object
- Object
- Hanami::Utils::Class
- Defined in:
- gems/gems/hanami-utils-1.3.3/lib/hanami/utils/class.rb,
gems/gems/hanami-utils-1.3.8/lib/hanami/utils/class.rb
Overview
Class utilities
Class Method Summary collapse
-
.load(name, namespace = Object) ⇒ Class, ...
Loads a class for the given name, only if it’s defined.
-
.load!(name, namespace = Object) ⇒ Class, Module
Loads a class for the given name.
-
.load_from_pattern!(pattern, namespace = Object) ⇒ Class, Module
Loads a class from the given pattern name and namespace.
-
.tokenize(pattern) ⇒ Object
rubocop:disable Metrics/MethodLength.
Class Method Details
.load(name, namespace = Object) ⇒ Class, ...
Loads a class for the given name, only if it’s defined.
Source: | on GitHub
def self.load(name, namespace = Object) load!(name, namespace) if namespace.const_defined?(name.to_s, false) end |
.load!(name, namespace = Object) ⇒ Class, Module
Loads a class for the given name.
Source: | on GitHub
def self.load!(name, namespace = Object) namespace.const_get(name.to_s, false) end |
.load_from_pattern!(pattern, namespace = Object) ⇒ Class, Module
Loads a class from the given pattern name and namespace
Source: | on GitHub
def self.load_from_pattern!(pattern, namespace = Object) Deprecation.new('Hanami::Utils::Class.load_from_pattern! is deprecated, please use Hanami::Utils::Class.load! instead') tokenize(pattern) do |token| begin return namespace.const_get(token, false) rescue NameError # rubocop:disable Lint/HandleExceptions end end full_name = [(namespace == Object ? nil : namespace), pattern].compact.join('::') raise NameError.new("uninitialized constant #{full_name}") end |
.tokenize(pattern) ⇒ Object
rubocop:disable Metrics/MethodLength
Source: | on GitHub
def self.tokenize(pattern) if match = TOKENIZE_REGEXP.match(pattern) # rubocop:disable Lint/AssignmentInCondition pre = match.pre_match post = match.post_match tokens = match[1].split(TOKENIZE_SEPARATOR) tokens.each do |token| yield("#{pre}#{token}#{post}") end else yield(pattern) end nil end |