Module: MaimaiNet::Page::HelperSupport
- Included in:
- Base
- Defined in:
- lib/maimai_net/page-html_helper.rb
Overview
adds capability to inject methods using hidden helper block
Class Method Summary collapse
-
.extended(cls) ⇒ void
automatically install mutex upon invoked for an extension.
Instance Method Summary collapse
-
#helper_method(meth, &block) ⇒ Symbol
defines the method to be injected with hidden helper block.
-
#method_added(meth) ⇒ void
install an auto-hook for data method for any Page::Base class.
Class Method Details
.extended(cls) ⇒ void
This method returns an undefined value.
automatically install mutex upon invoked for an extension
118 119 120 121 122 |
# File 'lib/maimai_net/page-html_helper.rb', line 118 def self.extended(cls) cls.class_exec do include ModuleExt::AddInternalMutex end end |
Instance Method Details
#helper_method(meth, &block) ⇒ Symbol
defines the method to be injected with hidden helper block. such method have an extended set of capability to use methods provided on HelperBlock class.
83 84 85 86 87 88 89 |
# File 'lib/maimai_net/page-html_helper.rb', line 83 def helper_method(meth, &block) lock :helper_method, meth do define_method meth do HelperBlock.__send__(:new, self).instance_exec(&block) end end end |
#method_added(meth) ⇒ void
This method returns an undefined value.
install an auto-hook for data method for any Page::Base class.
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/maimai_net/page-html_helper.rb', line 94 def method_added(meth) return super unless meth === :data && self <= Page::Base lock :helper_method, meth do fail NotImplementedError, "no solution found for method definition rebinding. please use helper_method #{meth.inspect} do ... end block instead." # rand_name = '_%0*x' % [0.size << 1, rand(1 << (0.size << 3))] old_meth = instance_method(meth) # obj = allocate # old_meth = obj.method(meth) # HelperBlock.define_method rand_name, old_meth # old_meth = instance_method(rand_name) # p old_meth # remove_method rand_name define_method meth do HelperBlock.__send__(:new, self).instance_exec(&old_meth.bind(self)) end super end end |