Module: ModuleShims::Switch
- Defined in:
- lib/module_shims/switch.rb
Instance Method Summary collapse
- #default_target ⇒ Object
- #disable_shim ⇒ Object
- #enable_shim(shadow_target = true) ⇒ Object
- #insert_shim ⇒ Object
- #shim_const ⇒ Object
- #target_const ⇒ Object
- #target_const=(target = default_target) ⇒ Object
Instance Method Details
#default_target ⇒ Object
35 36 37 |
# File 'lib/module_shims/switch.rb', line 35 def default_target const_get(name.gsub(/\A[^:]*/, '')) end |
#disable_shim ⇒ Object
9 10 11 12 |
# File 'lib/module_shims/switch.rb', line 9 def disable_shim target_const.prefix_existing_instance_methods('__module_switch', self, true) target_const.remove_instance_methods_from_ancestors("#{name}::SHIM") end |
#enable_shim(shadow_target = true) ⇒ Object
3 4 5 6 7 |
# File 'lib/module_shims/switch.rb', line 3 def enable_shim(shadow_target = true) insert_shim unless @inserted target_const.prefix_existing_instance_methods('__module_switch', self) if shadow_target shim_const.copy_existing_instance_methods(self) end |
#insert_shim ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/module_shims/switch.rb', line 14 def insert_shim @inserted ||= begin target_const.send(:prepend, shim_const) true end end |
#shim_const ⇒ Object
22 23 24 25 |
# File 'lib/module_shims/switch.rb', line 22 def shim_const @shim ||= const_defined?('SHIM') ? const_get('SHIM') : const_set('SHIM', Module.new{ def self.prepended(mod); mod.remove_instance_methods_from_ancestors(name); super; end }) end |
#target_const ⇒ Object
27 28 29 |
# File 'lib/module_shims/switch.rb', line 27 def target_const @target ||= default_target end |
#target_const=(target = default_target) ⇒ Object
31 32 33 |
# File 'lib/module_shims/switch.rb', line 31 def target_const=(target = default_target) @target = target end |