Class: ReloaderInterceptor::Wrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/reloader_interceptor/wrapper.rb

Defined Under Namespace

Modules: DSL

Class Method Summary collapse

Class Method Details

.wrap(klass) ⇒ Class

Returns A wrapping class. Return the original one if ‘ReloaderInterceptor` is disabled.

Parameters:

  • klass (Class)

    An original class.

Returns:

  • (Class)

    A wrapping class. Return the original one if ‘ReloaderInterceptor` is disabled.



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/reloader_interceptor/wrapper.rb', line 54

def wrap(klass)
  return klass unless ReloaderInterceptor.enabled?

  klass_name = klass.name
  Class.new(klass.superclass) do
    extend Wrapper::DSL

    # Define `.name`, `.inspect`, and `.to_s` to mimic the original class.
    self.define_singleton_method :name do
      klass_name
    end
    self.define_singleton_method :inspect do
      klass_name
    end
    self.define_singleton_method :to_s do
      klass_name
    end

    def initialize(*options)
      @options = options
    end

    define_instance_methods_using_class_name(self, klass)
    define_singleton_methods_using_class_name(self, klass)
  end
end