Sha256: 713453675155f8a107f111b0cc86f40aa3c6f7ef090dd4dc9ffccf3280f6c8d9

Contents?: true

Size: 1.46 KB

Versions: 3

Compression:

Stored size: 1.46 KB

Contents

require File.expand_path(File.join(File.dirname(__FILE__), 'v1', 'module_body_method_call_recorder'))
require File.expand_path(File.join(File.dirname(__FILE__), 'v1', 'singleton_method_definition_store'))

module SuperModule
  module V1
    class << self
      def included(original_base)
        original_base.class_eval do
          extend SuperModule::V1::ModuleBodyMethodCallRecorder
          extend SuperModule::V1::SingletonMethodDefinitionStore

          class << self
            def __define_super_module_singleton_methods(base)
              __super_module_singleton_methods.each do |method_name, method_body|
                # The following is needed for cases where a method is declared public/protected/private after it was added
                refreshed_access_level_method_body = method_body.sub(/class << self\n(public|protected|private)\n/, "class << self\n#{__singleton_method_access_level(method_name)}\n")
                base.class_eval(refreshed_access_level_method_body)
              end
            end

            def __invoke_module_body_method_calls(base)
              __all_module_body_method_calls_in_definition_order.each do |method_name, args, block|
                base.send(method_name, *args, &block)
              end
            end

            def included(base)
              __define_super_module_singleton_methods(base)
              __invoke_module_body_method_calls(base)
            end
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
super_module-1.2.2 lib/super_module/v1.rb
super_module-1.2.1 lib/super_module/v1.rb
super_module-1.2.0 lib/super_module/v1.rb