Module: Gruf::Autoloaders
- Extended by:
- Enumerable
- Defined in:
- lib/gruf/autoloaders.rb
Overview
Module for accessing Gruf zeitwerk-based autoloaders
Class Method Summary collapse
-
.controllers(controllers_path: nil) ⇒ ::Gruf::Controllers::Autoloader
Lazily instantiate and memoize the Gruf Controllers autoloader in a thread-safe manner.
-
.controllers_mutex(&block) ⇒ Object
Handle mutations to the controllers autoloader in a thread-safe manner.
-
.each {|controllers| ... } ⇒ Object
Enumerate across the managed set of autoloaders.
-
.load!(controllers_path:) ⇒ Object
Initialize the autoloaders with a given controllers path.
-
.reload ⇒ Object
Reload all files managed by the autoloader.
Class Method Details
.controllers(controllers_path: nil) ⇒ ::Gruf::Controllers::Autoloader
Lazily instantiate and memoize the Gruf Controllers autoloader in a thread-safe manner
rubocop:disable ThreadSafety/InstanceVariableInClassMethod
55 56 57 58 59 |
# File 'lib/gruf/autoloaders.rb', line 55 def controllers(controllers_path: nil) controllers_mutex do @controllers ||= ::Gruf::Controllers::Autoloader.new(path: controllers_path || ::Gruf.controllers_path) end end |
.controllers_mutex(&block) ⇒ Object
Handle mutations to the controllers autoloader in a thread-safe manner
rubocop:disable ThreadSafety/InstanceVariableInClassMethod
66 67 68 69 70 71 72 |
# File 'lib/gruf/autoloaders.rb', line 66 def controllers_mutex(&block) @controllers_mutex ||= begin require 'monitor' Monitor.new end @controllers_mutex.synchronize(&block) end |
.each {|controllers| ... } ⇒ Object
Enumerate across the managed set of autoloaders
38 39 40 |
# File 'lib/gruf/autoloaders.rb', line 38 def each yield controllers end |
.load!(controllers_path:) ⇒ Object
Initialize the autoloaders with a given controllers path
31 32 33 |
# File 'lib/gruf/autoloaders.rb', line 31 def load!(controllers_path:) controllers(controllers_path: controllers_path) end |
.reload ⇒ Object
Reload all files managed by the autoloader
45 46 47 |
# File 'lib/gruf/autoloaders.rb', line 45 def reload each(&:reload) end |