Module: CommandTest::CoreExtensions

Defined in:
lib/command_test/core_extensions.rb

Defined Under Namespace

Modules: IO, Kernel, Open3

Class Method Summary collapse

Class Method Details

.define_included_hook(mod, *methods) ⇒ Object

:nodoc:



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/command_test/core_extensions.rb', line 5

def self.define_included_hook(mod, *methods) # :nodoc:
  name_map = methods.last.is_a?(Hash) ? methods.pop : {}
  methods.each{|m| name_map[m] = m}
  aliasings = name_map.map do |name, massaged|
    <<-EOS
      unless method_defined?(:#{massaged}_without_command_test)
        alias #{massaged}_without_command_test #{name}
        alias #{name} #{massaged}_with_command_test
      end
    EOS
  end.join("\n")

  mod.module_eval <<-EOS
    def self.included(base)
      base.module_eval do
        #{aliasings}
      end
    end

    def self.extended(base)
      included((class << base; self; end))
    end
  EOS
end