Module: Nanoboy::Hook

Defined in:
lib/nanoboy/hook.rb

Overview

This module acts as a hook to enable Nanoboy in the class that includes it

Defined Under Namespace

Modules: ConstSetHook, InheritedHook, SymbolHook

Class Method Summary collapse

Class Method Details

.activateObject

Performs the hooking into the system that will make Nanoboy work



65
66
67
68
69
70
# File 'lib/nanoboy/hook.rb', line 65

def self.activate
  # Modules do not have Class#inherited since it is only defined for classes
  Class.instance_eval  { include InheritedHook }
  Module.instance_eval { include ConstSetHook  }
  Symbol.instance_eval { include SymbolHook    }
end

.included(klass) ⇒ Object

You can include Nanoboy::Hook manually in your classes. Useful if it’s activated too late for you



49
50
51
# File 'lib/nanoboy/hook.rb', line 49

def self.included(klass)
  klass.singleton_class.instance_eval { include InheritedHook, ConstSetHook }
end

.nanoboy_alias(klass, name) ⇒ Object

Similar to ActiveSupport alias_method_chain, but ensuring the alias is created only once



55
56
57
58
59
60
61
62
# File 'lib/nanoboy/hook.rb', line 55

def self.nanoboy_alias klass, name
  klass.class_eval do
    unless (instance_methods + private_methods).include? :"#{name}_without_nanoboy"
      alias_method "#{name}_without_nanoboy", name
      alias_method name, "#{name}_with_nanoboy"
    end
  end
end