Sha256: 7ae2c69299ffbf5da6ac7476c03f7b74b0ce3c5be2c4473c14db81a797ed63df

Contents?: true

Size: 1.46 KB

Versions: 11

Compression:

Stored size: 1.46 KB

Contents

class RecordingParent < BasicObject

  class << self

    def method_missing(m, *args, &block)
      __missing_class_macros__.push({ m => [args, block].compact })
    end

    def __missing_class_macros__
      @__missing_class_macros__ ||= []
    end

    module ConstMissing
      def const_missing(const_sym)
        if const_defined?("::#{const_sym}")
          Kernel.const_get("::#{const_sym}")
        else
          const = self.const_set(const_sym, Module.new)
          const.extend ConstMissing
          const.module_eval(<<-RUBY, __FILE__, __LINE__+1)
                    def self.name
                      "#{name.gsub(/#<Module:.*>::/, '')}::#{const_sym}"
                    end

                    def self.inspect
                      name
                    end
          RUBY
          RecordingParent.__missing_constants__[const_sym] = const
          const
        end
      end
    end

    include ConstMissing

    def __missing_constants__
      # This file and it's class variables are reinitialized within a new module namespace on every run.
      @@__missing_constants__ ||= {}
    end

    def listen_to_defined_macros(*methods)
      methods.each do |m|
        module_eval(<<-RUBY, __FILE__)
          def self.#{m}(*args, &block)
            __missing_class_macros__.push({ __method__ => [args, block].compact })
          end
        RUBY
      end
    end
  end

  listen_to_defined_macros *DissociatedIntrospection.listen_to_defined_class_methods
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
dissociated_introspection-0.9.1 lib/dissociated_introspection/recording_parent.rb
dissociated_introspection-0.9.0 lib/dissociated_introspection/recording_parent.rb
dissociated_introspection-0.8.4 lib/dissociated_introspection/recording_parent.rb
dissociated_introspection-0.8.3 lib/dissociated_introspection/recording_parent.rb
dissociated_introspection-0.8.2 lib/dissociated_introspection/recording_parent.rb
dissociated_introspection-0.8.1 lib/dissociated_introspection/recording_parent.rb
dissociated_introspection-0.8.0 lib/dissociated_introspection/recording_parent.rb
dissociated_introspection-0.7.1 lib/dissociated_introspection/recording_parent.rb
dissociated_introspection-0.7.0 lib/dissociated_introspection/recording_parent.rb
dissociated_introspection-0.6.0 lib/dissociated_introspection/recording_parent.rb
dissociated_introspection-0.5.0 lib/dissociated_introspection/recording_parent.rb