Class: Ivar::CheckAllManager
- Inherits:
-
Object
- Object
- Ivar::CheckAllManager
- Defined in:
- lib/ivar/check_all_manager.rb
Overview
Manages automatic inclusion of Ivar::Checked in classes and modules
Instance Method Summary collapse
-
#disable ⇒ void
Disables automatic inclusion of Ivar::Checked in classes and modules.
-
#enable(project_root, &block) ⇒ void
Enables automatic inclusion of Ivar::Checked in all classes and modules defined within the project root.
-
#enabled? ⇒ Boolean
Returns whether check_all is currently enabled.
-
#initialize ⇒ CheckAllManager
constructor
A new instance of CheckAllManager.
-
#trace_point ⇒ TracePoint?
Returns the current trace point (mainly for testing).
Constructor Details
#initialize ⇒ CheckAllManager
Returns a new instance of CheckAllManager.
8 9 10 11 |
# File 'lib/ivar/check_all_manager.rb', line 8 def initialize @trace_point = nil @mutex = Mutex.new end |
Instance Method Details
#disable ⇒ void
This method returns an undefined value.
Disables automatic inclusion of Ivar::Checked in classes and modules.
51 52 53 54 55 56 57 58 |
# File 'lib/ivar/check_all_manager.rb', line 51 def disable @mutex.synchronize do if @trace_point @trace_point.disable @trace_point = nil end end end |
#enable(project_root, &block) ⇒ void
This method returns an undefined value.
Enables automatic inclusion of Ivar::Checked in all classes and modules defined within the project root.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/ivar/check_all_manager.rb', line 20 def enable(project_root, &block) disable if @trace_point root_pathname = Pathname.new(project_root) @mutex.synchronize do # :end means "end of module or class definition" in TracePoint @trace_point = TracePoint.new(:end) do |tp| next unless tp.path file_path = Pathname.new(File.(tp.path)) if file_path.to_s.start_with?(root_pathname.to_s) klass = tp.self next if klass.included_modules.include?(Ivar::Checked) klass.include(Ivar::Checked) end end @trace_point.enable end if block begin yield ensure disable end end nil end |
#enabled? ⇒ Boolean
Returns whether check_all is currently enabled
62 63 64 |
# File 'lib/ivar/check_all_manager.rb', line 62 def enabled? @mutex.synchronize { !@trace_point.nil? && @trace_point.enabled? } end |
#trace_point ⇒ TracePoint?
Returns the current trace point (mainly for testing)
68 69 70 |
# File 'lib/ivar/check_all_manager.rb', line 68 def trace_point @mutex.synchronize { @trace_point } end |