Class: PoiseProfiler::Base Private
- Inherits:
-
Chef::EventDispatch::Base
- Object
- Chef::EventDispatch::Base
- PoiseProfiler::Base
- Includes:
- Singleton
- Defined in:
- lib/poise_profiler/base.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Base class for poise-provider event handlers.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#events ⇒ Object
writeonly
private
Used in #_monkey_patch_old_chef.
-
#monkey_patched ⇒ Object
writeonly
private
Used in #_monkey_patch_old_chef.
Class Method Summary collapse
-
.install! ⇒ void
private
Install this event handler in to Chef.
Instance Method Summary collapse
-
#_monkey_patch_old_chef! ⇒ void
private
Inject this instance for Chef < 12.3.
-
#reset! ⇒ void
private
Hook to reset the handler for testing.
Instance Attribute Details
#events=(value) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Used in #_monkey_patch_old_chef.
61 62 63 |
# File 'lib/poise_profiler/base.rb', line 61 def events=(value) @events = value end |
#monkey_patched=(value) ⇒ Object (writeonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Used in #_monkey_patch_old_chef.
61 62 63 |
# File 'lib/poise_profiler/base.rb', line 61 def monkey_patched=(value) @monkey_patched = value end |
Class Method Details
.install! ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Install this event handler in to Chef.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/poise_profiler/base.rb', line 39 def self.install! # Clear instance state to be safe. instance.reset! # For pre-Chef.run_context, use the monkey patch. Otherwise use the # events API or global config. if Gem::Version.create(Chef::VERSION) <= Gem::Version.create('12.2.1') Chef::Log.debug("Registering poise-profiler handler #{self} using monkey patch") instance._monkey_patch_old_chef! elsif Chef.run_context && Chef.run_context.events # :nocov: Chef::Log.debug("Registering poise-profiler handler #{self} using events API") Chef.run_context.events.register(instance) # :nocov: else Chef::Log.debug("Registering poise-profiler handler #{self} using global config") Chef::Config[:event_handlers] |= [instance] end end |
Instance Method Details
#_monkey_patch_old_chef! ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Inject this instance for Chef < 12.3. Don’t call this on newer Chef.
76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/poise_profiler/base.rb', line 76 def _monkey_patch_old_chef! require 'chef/event_dispatch/dispatcher' instance = self orig_method = Chef::EventDispatch::Dispatcher.instance_method(:library_file_loaded) Chef::EventDispatch::Dispatcher.send(:define_method, :library_file_loaded) do |filename| instance.events = self instance.monkey_patched = false @subscribers |= [instance] Chef::EventDispatch::Dispatcher.send(:define_method, :library_file_loaded, orig_method) orig_method.bind(self).call(filename) end end |
#reset! ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Hook to reset the handler for testing.
67 68 69 |
# File 'lib/poise_profiler/base.rb', line 67 def reset! @events = nil end |