Sha256: d88673ff4991277ee4b2b6e43894689f97290db75253c762395d04b49df5b714

Contents?: true

Size: 616 Bytes

Versions: 18

Compression:

Stored size: 616 Bytes

Contents

require "securerandom"

module Support
  module MethodPatchMacro

    def self.included(base)
      base.extend ClassMethods
    end

    module ClassMethods
      def with_module_method(mod, meth, &block)
        tag = SecureRandom.hex(8)
        orig_meth = "_#{tag}_#{meth}".to_sym
        before do
          mod.module_eval do
            alias_method orig_meth, meth
            define_method meth, &block
          end
        end
        after do
          mod.module_eval do
            alias_method meth, orig_meth
            remove_method orig_meth
          end
        end
      end
    end

  end
end

Version data entries

18 entries across 18 versions & 2 rubygems

Version Path
librarianp-1.1.2 spec/support/method_patch_macro.rb
librarianp-1.1.1 spec/support/method_patch_macro.rb
librarianp-1.1.0 spec/support/method_patch_macro.rb
librarianp-1.0.0 spec/support/method_patch_macro.rb
librarianp-0.6.4 spec/support/method_patch_macro.rb
librarianp-0.6.3 spec/support/method_patch_macro.rb
librarianp-0.6.2 spec/support/method_patch_macro.rb
librarianp-0.6.1 spec/support/method_patch_macro.rb
librarianp-0.6.0 spec/support/method_patch_macro.rb
librarianp-0.5.1 spec/support/method_patch_macro.rb
librarianp-0.5.0 spec/support/method_patch_macro.rb
librarianp-0.4.0 spec/support/method_patch_macro.rb
librarianp-0.3.0 spec/support/method_patch_macro.rb
librarianp-0.2.0 spec/support/method_patch_macro.rb
librarianp-0.1.2 spec/support/method_patch_macro.rb
librarian-0.1.2 spec/support/method_patch_macro.rb
librarian-0.1.1 spec/support/method_patch_macro.rb
librarian-0.1.0 spec/support/method_patch_macro.rb