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
167 168 169 170 171 |
# File 'lib/maimai_net/page-html_helper.rb', line 167 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.
132 133 134 135 136 137 138 |
# File 'lib/maimai_net/page-html_helper.rb', line 132 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.
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/maimai_net/page-html_helper.rb', line 143 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 |