Module: MoreCoreExtensions::StringConstantizeAllowlist
- Defined in:
- lib/more_core_extensions/core_ext/string/constantize_allowlist.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.allowed?(target, allowlist) ⇒ Boolean
5 6 7 8 |
# File 'lib/more_core_extensions/core_ext/string/constantize_allowlist.rb', line 5 def self.allowed?(target, allowlist) allowlist = allowlist.map { |o| o.respond_to?(:name) ? o.name : o } allowlist.include?(target) end |
Instance Method Details
#constantize(allowlist: nil) ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/more_core_extensions/core_ext/string/constantize_allowlist.rb', line 10 def constantize(allowlist: nil) if allowlist && !StringConstantizeAllowlist.allowed?(self, allowlist) raise NameError, "#{self} not found in allowlist" end super() end |
#safe_constantize(allowlist: nil) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/more_core_extensions/core_ext/string/constantize_allowlist.rb', line 18 def safe_constantize(allowlist: nil) if allowlist && !StringConstantizeAllowlist.allowed?(self, allowlist) return nil end super() end |