Class: ContextR::Layer
Instance Method Summary collapse
- #activated ⇒ Object
- #add_method_collection(contextified_class, methods_module) ⇒ Object
- #context_proxy(contextified_class, method_name) ⇒ Object
- #deactivated ⇒ Object
-
#definitions ⇒ Object
:nodoc: all.
- #inspect ⇒ Object (also: #to_s)
- #methods_module_containing_method(contextified_class, method_name) ⇒ Object
- #on_class_method_added(contextified_class, method_name, version) ⇒ Object
- #on_wrapper_method_added(methods_module, method_name, version) ⇒ Object
- #proxies ⇒ Object
- #register_callbacks(cclass, mmodule) ⇒ Object
- #replace_core_method(contextified_class, method_name, version) ⇒ Object
Instance Method Details
#activated ⇒ Object
3 4 5 |
# File 'lib/contextr/layer.rb', line 3 def activated nil end |
#add_method_collection(contextified_class, methods_module) ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/contextr/layer.rb', line 22 def add_method_collection(contextified_class, methods_module) definitions[contextified_class] = methods_module (methods_module.instance_methods & contextified_class.instance_methods).each do | method_name | replace_core_method(contextified_class, method_name, 0) end register_callbacks(contextified_class, methods_module) end |
#context_proxy(contextified_class, method_name) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/contextr/layer.rb', line 39 def context_proxy(contextified_class, method_name) methods_module = methods_module_containing_method(contextified_class, method_name) if methods_module proxies[methods_module] ||= begin p = ContextR::InnerClass.new class << p; self; end.class_eval do include(methods_module) end p end end end |
#deactivated ⇒ Object
6 7 8 |
# File 'lib/contextr/layer.rb', line 6 def deactivated nil end |
#definitions ⇒ Object
:nodoc: all
15 16 17 |
# File 'lib/contextr/layer.rb', line 15 def definitions @definitions ||= {} end |
#inspect ⇒ Object Also known as: to_s
9 10 11 |
# File 'lib/contextr/layer.rb', line 9 def inspect "ContextR::layer(:#{ContextR::symbol_by_layer(self)})" end |
#methods_module_containing_method(contextified_class, method_name) ⇒ Object
32 33 34 35 36 37 |
# File 'lib/contextr/layer.rb', line 32 def methods_module_containing_method(contextified_class, method_name) if definitions.include?(contextified_class) and definitions[contextified_class].instance_methods.include?(method_name.to_s) definitions[contextified_class] end end |
#on_class_method_added(contextified_class, method_name, version) ⇒ Object
54 55 56 57 58 |
# File 'lib/contextr/layer.rb', line 54 def on_class_method_added(contextified_class, method_name, version) if methods_module_containing_method(contextified_class, method_name) replace_core_method(contextified_class, method_name, version) end end |
#on_wrapper_method_added(methods_module, method_name, version) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/contextr/layer.rb', line 60 def on_wrapper_method_added(methods_module, method_name, version) self.definitions.collect do | each_class, each_methods_modules | if each_methods_modules.include?(methods_module) each_class end end.compact.select do |contextified_class| contextified_class.instance_methods.include?(method_name.to_s) end.each do | contextified_class | replace_core_method(contextified_class, method_name, 0) end end |
#proxies ⇒ Object
18 19 20 |
# File 'lib/contextr/layer.rb', line 18 def proxies @proxies ||= {} end |
#register_callbacks(cclass, mmodule) ⇒ Object
77 78 79 80 81 82 83 84 |
# File 'lib/contextr/layer.rb', line 77 def register_callbacks(cclass, mmodule) {:on_wrapper_method_added => mmodule, :on_class_method_added => cclass }.each do | callback, klass | ContextR::EventMachine.register(self, callback, :on_event => :method_added, :in_class => klass) end end |
#replace_core_method(contextified_class, method_name, version) ⇒ Object
72 73 74 75 |
# File 'lib/contextr/layer.rb', line 72 def replace_core_method(contextified_class, method_name, version) ContextR::observe_core_method(contextified_class, method_name.to_sym, version) end |