Module: Nyanko::UnitProxyProvider
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/nyanko/unit_proxy_provider.rb
Instance Method Summary collapse
-
#method_missing(method_name, *args, &block) ⇒ Object
Define #unit method in this class when #unit is called in first time.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
Define #unit method in this class when #unit is called in first time. Change Config.proxy_method_name if you want to change this method name.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/nyanko/unit_proxy_provider.rb', line 11 def method_missing(method_name, *args, &block) if Array.wrap(Config.proxy_method_name).include?(method_name) UnitProxyProvider.class_eval do define_method(method_name) do |*_args| name = _args.first || Function.current_unit.try(:unit_name) if name && unit = Loader.load(name) UnitProxy.new(unit, self) end end end send(method_name, args.first) else super end end |