Module: MuchPlugin::ClassMethods
- Defined in:
- lib/much-plugin.rb
Instance Method Summary collapse
- #after_plugin_included(&block) ⇒ Object
-
#included(plugin_receiver) ⇒ Object
install an included block that first checks if this plugin’s receiver mixin has already been included.
- #much_plugin_after_included_blocks ⇒ Object
- #much_plugin_class_method_blocks ⇒ Object
- #much_plugin_class_methods_module ⇒ Object
- #much_plugin_included_blocks ⇒ Object
-
#much_plugin_included_detector ⇒ Object
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-plugin.
- #much_plugin_instance_method_blocks ⇒ Object
- #much_plugin_instance_methods_module ⇒ Object
- #plugin_class_methods(&block) ⇒ Object
- #plugin_included(&block) ⇒ Object
- #plugin_instance_methods(&block) ⇒ Object
Instance Method Details
#after_plugin_included(&block) ⇒ Object
80 81 82 |
# File 'lib/much-plugin.rb', line 80 def after_plugin_included(&block) self.much_plugin_after_included_blocks << block end |
#included(plugin_receiver) ⇒ Object
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 ‘plugin_included` blocks
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/much-plugin.rb', line 14 def included(plugin_receiver) return if plugin_receiver.include?(self.much_plugin_included_detector) plugin_receiver.send(:include, self.much_plugin_included_detector) self.much_plugin_included_blocks.each do |block| plugin_receiver.class_eval(&block) end self.much_plugin_class_method_blocks.each do |block| self.much_plugin_class_methods_module.class_eval(&block) end plugin_receiver.send(:extend, self.much_plugin_class_methods_module) self.much_plugin_instance_method_blocks.each do |block| self.much_plugin_instance_methods_module.class_eval(&block) end plugin_receiver.send(:include, self.much_plugin_instance_methods_module) self.much_plugin_after_included_blocks.each do |block| plugin_receiver.class_eval(&block) end end |
#much_plugin_after_included_blocks ⇒ Object
64 65 66 |
# File 'lib/much-plugin.rb', line 64 def much_plugin_after_included_blocks @much_plugin_after_included_blocks ||= [] end |
#much_plugin_class_method_blocks ⇒ Object
68 69 70 |
# File 'lib/much-plugin.rb', line 68 def much_plugin_class_method_blocks @much_plugin_class_method_blocks ||= [] end |
#much_plugin_class_methods_module ⇒ Object
48 49 50 51 52 |
# File 'lib/much-plugin.rb', line 48 def much_plugin_class_methods_module @much_plugin_class_methods_module ||= Module.new.tap do |m| self.const_set("MuchPluginClassMethods", m) end end |
#much_plugin_included_blocks ⇒ Object
60 61 62 |
# File 'lib/much-plugin.rb', line 60 def much_plugin_included_blocks @much_plugin_included_blocks ||= [] end |
#much_plugin_included_detector ⇒ Object
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-plugin
42 43 44 45 46 |
# File 'lib/much-plugin.rb', line 42 def much_plugin_included_detector @much_plugin_included_detector ||= Module.new.tap do |m| self.const_set("MuchPluginIncludedDetector", m) end end |
#much_plugin_instance_method_blocks ⇒ Object
72 73 74 |
# File 'lib/much-plugin.rb', line 72 def much_plugin_instance_method_blocks @much_plugin_instance_method_blocks ||= [] end |
#much_plugin_instance_methods_module ⇒ Object
54 55 56 57 58 |
# File 'lib/much-plugin.rb', line 54 def much_plugin_instance_methods_module @much_plugin_instance_methods_module ||= Module.new.tap do |m| self.const_set("MuchPluginInstanceMethods", m) end end |
#plugin_class_methods(&block) ⇒ Object
84 85 86 |
# File 'lib/much-plugin.rb', line 84 def plugin_class_methods(&block) self.much_plugin_class_method_blocks << block end |
#plugin_included(&block) ⇒ Object
76 77 78 |
# File 'lib/much-plugin.rb', line 76 def plugin_included(&block) self.much_plugin_included_blocks << block end |
#plugin_instance_methods(&block) ⇒ Object
88 89 90 |
# File 'lib/much-plugin.rb', line 88 def plugin_instance_methods(&block) self.much_plugin_instance_method_blocks << block end |