Sha256: 2e01a74f854b356e368a382b0d65990f5c05e781b755167aa0c9e8f3f1163cae
Contents?: true
Size: 774 Bytes
Versions: 75
Compression:
Stored size: 774 Bytes
Contents
module Coco class ComponentResolver CLASS_CACHE = {} delegate_missing_to :@klass def initialize(klass, *args, **kwargs) @klass = klass @args = args @kwargs = kwargs end def render_in(view_context, ...) view_context.render(instance, ...) end def instance @_instance ||= @klass.new(*@args, **@kwargs) end class << self def new(target, *args, **kwargs) klass = target.is_a?(String) ? lookup_class(target) : target if args.any? || kwargs.any? klass.new(*args, **kwargs) else super(klass, *args, **kwargs) end end def lookup_class(path) CLASS_CACHE[path] ||= path.tr("-", "_").camelize.constantize end end end end
Version data entries
75 entries across 75 versions & 1 rubygems