Module: Hooki

Defined in:
lib/hooki.rb,
lib/hooki/version.rb,
lib/hooki/internal.rb,
lib/hooki/class_methods.rb

Defined Under Namespace

Modules: ClassMethods, Internal

Constant Summary collapse

INSTANCE_VARIABLE_LIST =
i[
  @before_method_callbacks @before_singleton_method_callbacks
  @after_method_callbacks @after_singleton_method_callbacks
  @ignore_methods @ignore_singleton_methods
].freeze
VERSION =
"0.1.0"

Class Method Summary collapse

Class Method Details

.hooki(klass) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/hooki.rb', line 24

def self.hooki(klass)
  klass.extend(Hooki::ClassMethods)
  klass.instance_variable_set(:@lock, Mutex.new)
  INSTANCE_VARIABLE_LIST.each do |instance_variable|
    klass.instance_variable_set(instance_variable, [])
  end

  klass.instance_variable_set(:@ignore_singleton_methods, i[included extended])

  def klass.included(klass)
    super
    Hooki.rehooki(self, klass)
  end

  def klass.prepended(klass)
    super
    Hooki.rehooki(self, klass)
  end

  def klass.inherited(klass)
    super
    Hooki.rehooki(self, klass)
  end

  def klass.append_features(mod)
    super
    mod.include(Hooki) # Notice this
    Hooki.rehooki(self, mod)
  end
end

.included(klass) ⇒ Object



14
15
16
# File 'lib/hooki.rb', line 14

def self.included(klass)
  hooki(klass)
end

.prepended(klass) ⇒ Object



10
11
12
# File 'lib/hooki.rb', line 10

def self.prepended(klass)
  hooki(klass)
end

.rehooki(parent, child) ⇒ Object



55
56
57
58
59
# File 'lib/hooki.rb', line 55

def self.rehooki(parent, child)
  INSTANCE_VARIABLE_LIST.each do |instance_variable|
    child.instance_variable_set(instance_variable, parent.instance_variable_get(instance_variable))
  end
end