Class: RequireProfiler::Plugins::YAMLPlugin

Inherits:
Base
  • Object
show all
Defined in:
lib/require_profiler/plugins/yaml_plugin.rb

Overview

Track loading YAML files

Defined Under Namespace

Modules: Patch

Class Attribute Summary collapse

Attributes inherited from Base

#reporter

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from RequireProfiler::Plugins::Base

Class Attribute Details

.reporterObject

Returns the value of attribute reporter.



22
23
24
# File 'lib/require_profiler/plugins/yaml_plugin.rb', line 22

def reporter
  @reporter
end

Class Method Details

.track(path) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/require_profiler/plugins/yaml_plugin.rb', line 24

def track(path)
  reporter.handle_event(Reporter::Event.new(type: :start, kind: :yml, path:))
  start = Time.now
  yield
ensure
  time = Time.now - start
  reporter.handle_event(Reporter::Event.new(type: :end, path:, time:))
end

Instance Method Details

#activate!Object



34
35
36
37
38
39
# File 'lib/require_profiler/plugins/yaml_plugin.rb', line 34

def activate!
  require "yaml"

  YAMLPlugin.reporter = reporter
  ::YAML.singleton_class.prepend(Patch)
end