module SomeModule
extend ActiveSupport::Concern
included do
include Hooks
define_hooks :myhook1
end
end
class MyClass
include Hooks
define_hooks :myhook2
include SomeModule
def run_myhook1
run_hook :myhook1
end
def run_myhook2
run_hook :myhook2
end
end
MyClass._hooks # => {:myhook1=>[]}
MyClass.new.run_myhook1 # => Works fine
MyClass.new.run_myhook2 # => NoMethodError: undefined method `run' for nil:NilClass
This seems to be because the following code in lib/hooks.rb runs on every include:
# lib/hooks.rb
module Hooks
def self.included(base)
base.class_eval do
extend Uber::InheritableAttr
extend ClassMethods
inheritable_attr :_hooks
self._hooks= HookSet.new # <-- this wipes out existing hooks
end
end