Module: RailsDevelopmentBoost::ObservablePatch
- Extended by:
- ObservablePatch
- Included in:
- ObservablePatch
- Defined in:
- lib/rails_development_boost/observable_patch.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.apply! ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/rails_development_boost/observable_patch.rb', line 5 def self.apply! patch = self if non_ruby_lib_implementation? ActiveModel::Observing::ClassMethods # post c2ca73c9 compatibility else require 'observer' Observable end.class_eval do include patch alias_method_chain :add_observer, :unloading end end |
.non_ruby_lib_implementation? ⇒ Boolean
19 20 21 |
# File 'lib/rails_development_boost/observable_patch.rb', line 19 def self.non_ruby_lib_implementation? defined?(ActiveModel::Observing::ClassMethods) && ActiveModel::Observing::ClassMethods.public_instance_methods(false).map(&:to_s).include?('add_observer') end |
Instance Method Details
#_get_module(object) ⇒ Object
34 35 36 |
# File 'lib/rails_development_boost/observable_patch.rb', line 34 def _get_module(object) object.kind_of?(Module) ? object : object.class end |
#add_observer_with_unloading(*args) ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/rails_development_boost/observable_patch.rb', line 23 def add_observer_with_unloading(*args) if kind_of?(Module) my_module, observer_module = ObservablePatch._get_module(self), ObservablePatch._get_module(args.first) ActiveSupport::Dependencies.add_explicit_dependency(my_module, observer_module) ActiveSupport::Dependencies.add_explicit_dependency(observer_module, my_module) end add_observer_without_unloading(*args) end |