lib/much-mixin.rb in much-mixin-0.0.1 vs lib/much-mixin.rb in much-mixin-0.2.3

- old
+ new

@@ -6,41 +6,41 @@ def self.included(receiver) receiver.class_eval{ extend ClassMethods } end module ClassMethods - # install an included block that first checks if this plugin's receiver mixin - # has already been included. If it has not been, include the receiver mixin - # and run all of the `mixin_included` blocks - def included(plugin_receiver) - return if plugin_receiver.include?(self.much_mixin_included_detector) - plugin_receiver.send(:include, self.much_mixin_included_detector) + # Install an included block that first checks if the mix-in has already been + # included. If it has not been, include the receiver mixin and run all of + # the `mixin_included` blocks. + def included(mixin_receiver) + return if mixin_receiver.include?(self.much_mixin_included_detector) + mixin_receiver.send(:include, self.much_mixin_included_detector) self.much_mixin_included_blocks.each do |block| - plugin_receiver.class_eval(&block) + mixin_receiver.class_eval(&block) end - self.much_plugin_class_method_blocks.each do |block| + self.much_mixin_class_method_blocks.each do |block| self.much_mixin_class_methods_module.class_eval(&block) end - plugin_receiver.send(:extend, self.much_mixin_class_methods_module) + mixin_receiver.send(:extend, self.much_mixin_class_methods_module) - self.much_plugin_instance_method_blocks.each do |block| + self.much_mixin_instance_method_blocks.each do |block| self.much_mixin_instance_methods_module.class_eval(&block) end - plugin_receiver.send(:include, self.much_mixin_instance_methods_module) + mixin_receiver.send(:include, self.much_mixin_instance_methods_module) - self.much_plugin_after_included_blocks.each do |block| - plugin_receiver.class_eval(&block) + self.much_mixin_after_included_blocks.each do |block| + mixin_receiver.class_eval(&block) end end - # the included detector is an empty module that is only used to detect if - # the plugin has been included or not, it doesn't add any behavior or - # methods to the object receiving the plugin; we use `const_set` to name the - # module so if its seen in the ancestors it doesn't look like some random - # module and it can be tracked back to much-mixin + # The included detector is an empty module that is only used to detect if + # the mix-in has been included or not. It doesn't add any behavior or + # methods to the receiver and uses `const_set` to name the module so if its + # seen in the ancestors it doesn't look like some random module and it can + # be tracked back to much-mixin. def much_mixin_included_detector @much_mixin_included_detector ||= Module.new.tap do |m| self.const_set("MuchMixinIncludedDetector", m) end end @@ -59,38 +59,34 @@ def much_mixin_included_blocks @much_mixin_included_blocks ||= [] end - def much_plugin_after_included_blocks - @much_plugin_after_included_blocks ||= [] + def much_mixin_after_included_blocks + @much_mixin_after_included_blocks ||= [] end - def much_plugin_class_method_blocks - @much_plugin_class_method_blocks ||= [] + def much_mixin_class_method_blocks + @much_mixin_class_method_blocks ||= [] end - def much_plugin_instance_method_blocks - @much_plugin_instance_method_blocks ||= [] + def much_mixin_instance_method_blocks + @much_mixin_instance_method_blocks ||= [] end def mixin_included(&block) self.much_mixin_included_blocks << block end - alias_method :plugin_included, :mixin_included def after_mixin_included(&block) - self.much_plugin_after_included_blocks << block + self.much_mixin_after_included_blocks << block end - alias_method :after_plugin_included, :after_mixin_included def mixin_class_methods(&block) - self.much_plugin_class_method_blocks << block + self.much_mixin_class_method_blocks << block end - alias_method :plugin_class_methods, :mixin_class_methods def mixin_instance_methods(&block) - self.much_plugin_instance_method_blocks << block + self.much_mixin_instance_method_blocks << block end - alias_method :plugin_instance_methods, :mixin_instance_methods end end