lib/interloper.rb in interloper-0.2.1 vs lib/interloper.rb in interloper-0.2.2

- old
+ new

@@ -24,15 +24,15 @@ # class, if one does not already exist. Then prepends the Interloper # module to the including class. # @return Module the Interloper module that was prepended to the including # class. def interloper_module - unless prepended? interloper_const_name + @interloper_module ||= begin const_set(interloper_const_name, generate_interloper_module) prepend const_get(interloper_const_name) + const_get(interloper_const_name) end - const_get(interloper_const_name) end # @return Boolean True if the interloper module has already been prepnded;] # false otherwise. def prepended?(const_name) @@ -137,24 +137,24 @@ inherit_callbacks_before(*method_names) inherit_callbacks_after(*method_names) end def inherit_callbacks_before(*method_names) - inherited_callbacks(:before, *method_names).each do |callback| + ancestor_callbacks(:before, *method_names).each do |callback| before(*method_names, &callback) end end def inherit_callbacks_after(*method_names) - inherited_callbacks(:after, *method_names).each do |callback| + ancestor_callbacks(:after, *method_names).each do |callback| after(*method_names, &callback) end end - def inherited_callbacks(hook, *method_names) + def ancestor_callbacks(hook, *method_names) method_names.map do |method_name| ancestor_interloper_module.callbacks[hook][method_name] - end.flatten + end.flatten.compact end # @return [Module] The nearest ancstors tha is an interloper module. def ancestor_interloper_module ancestors.detect do |ancestor|