Module: PathMapper::Reloader

Included in:
DirNode, FileNode, NullNode
Defined in:
lib/path_mapper/reloader.rb

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/path_mapper/reloader.rb', line 3

def self.included(base)
  base.class_eval do
    methods = base.public_instance_methods - Object.public_instance_methods
    methods.each do |name|
      with = :"#{name}_with_reload"
      without = :"#{name}_without_reload"
      @__last_methods_added = [name, with, without]

      define_method with do |*args, &block|
        obj = self._create_node(@path)
        if obj.is_a? self.class
          self.send(without, *args, &block)
        else
          obj.send(without, *args, &block)
        end
      end

      alias_method without, name
      alias_method name, with
    end
  end
end