Class: HomuraRuntime::AsyncRegistry
- Inherits:
-
Object
- Object
- HomuraRuntime::AsyncRegistry
- Defined in:
- lib/homura/runtime/async_registry.rb
Defined Under Namespace
Classes: Builder
Instance Attribute Summary collapse
-
#async_accessors ⇒ Object
readonly
Returns the value of attribute async_accessors.
-
#async_classes ⇒ Object
readonly
Returns the value of attribute async_classes.
-
#async_factories ⇒ Object
readonly
Returns the value of attribute async_factories.
-
#async_helpers ⇒ Object
readonly
Returns the value of attribute async_helpers.
-
#async_methods ⇒ Object
readonly
Returns the value of attribute async_methods.
-
#helper_factories ⇒ Object
readonly
Returns the value of attribute helper_factories.
-
#taint_returns ⇒ Object
readonly
Returns the value of attribute taint_returns.
Class Method Summary collapse
- .async?(class_name, method_name) ⇒ Boolean
- .auto_load_gem_async_sources(debug: false) ⇒ Object
- .factory?(class_name, method_name) ⇒ Boolean
- .instance ⇒ Object
- .register_async_source(&block) ⇒ Object
- .reset! ⇒ Object
- .taint_return_class(class_name, method_name) ⇒ Object
- .tainted_class?(class_name) ⇒ Boolean
Instance Method Summary collapse
- #async?(class_name, method_name) ⇒ Boolean
- #factory?(class_name, method_name) ⇒ Boolean
-
#initialize ⇒ AsyncRegistry
constructor
A new instance of AsyncRegistry.
- #taint_return_class(class_name, method_name) ⇒ Object
- #tainted_class?(class_name) ⇒ Boolean
Constructor Details
#initialize ⇒ AsyncRegistry
Returns a new instance of AsyncRegistry.
123 124 125 126 127 128 129 130 131 |
# File 'lib/homura/runtime/async_registry.rb', line 123 def initialize @async_classes = {} @async_methods = {} @async_factories = {} @taint_returns = {} @async_accessors = {} @async_helpers = {} @helper_factories = {} end |
Instance Attribute Details
#async_accessors ⇒ Object (readonly)
Returns the value of attribute async_accessors.
115 116 117 |
# File 'lib/homura/runtime/async_registry.rb', line 115 def async_accessors @async_accessors end |
#async_classes ⇒ Object (readonly)
Returns the value of attribute async_classes.
115 116 117 |
# File 'lib/homura/runtime/async_registry.rb', line 115 def async_classes @async_classes end |
#async_factories ⇒ Object (readonly)
Returns the value of attribute async_factories.
115 116 117 |
# File 'lib/homura/runtime/async_registry.rb', line 115 def async_factories @async_factories end |
#async_helpers ⇒ Object (readonly)
Returns the value of attribute async_helpers.
115 116 117 |
# File 'lib/homura/runtime/async_registry.rb', line 115 def async_helpers @async_helpers end |
#async_methods ⇒ Object (readonly)
Returns the value of attribute async_methods.
115 116 117 |
# File 'lib/homura/runtime/async_registry.rb', line 115 def async_methods @async_methods end |
#helper_factories ⇒ Object (readonly)
Returns the value of attribute helper_factories.
115 116 117 |
# File 'lib/homura/runtime/async_registry.rb', line 115 def helper_factories @helper_factories end |
#taint_returns ⇒ Object (readonly)
Returns the value of attribute taint_returns.
115 116 117 |
# File 'lib/homura/runtime/async_registry.rb', line 115 def taint_returns @taint_returns end |
Class Method Details
.async?(class_name, method_name) ⇒ Boolean
59 60 61 |
# File 'lib/homura/runtime/async_registry.rb', line 59 def async?(class_name, method_name) instance.async?(class_name, method_name) end |
.auto_load_gem_async_sources(debug: false) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/homura/runtime/async_registry.rb', line 75 def auto_load_gem_async_sources(debug: false) return unless defined?(Gem) && Gem.respond_to?(:loaded_specs) loaded = 0 Gem.loaded_specs.each_value do |spec| next if spec.full_gem_path.nil? lib_dir = File.join(spec.full_gem_path, "lib") next unless Dir.exist?(lib_dir) Dir .glob(File.join(lib_dir, "**", "*.rb")) .each do |path| next unless File.read(path).include?("register_async_source") require_path = path.sub(Regexp.new("^#{Regexp.escape(lib_dir)}/"), "").sub( /\.rb\z/, "" ) begin require require_path loaded += 1 if debug puts "[auto-await] loaded async source from #{spec.name}: #{require_path}" end rescue LoadError, StandardError => e if debug warn "[auto-await] Warning: failed to load async source from #{spec.name}/#{require_path}: #{e.}" end end end end if debug && loaded.positive? puts "[auto-await] auto-loaded #{loaded} async source file(s)" end end |
.factory?(class_name, method_name) ⇒ Boolean
63 64 65 |
# File 'lib/homura/runtime/async_registry.rb', line 63 def factory?(class_name, method_name) instance.factory?(class_name, method_name) end |
.instance ⇒ Object
51 52 53 |
# File 'lib/homura/runtime/async_registry.rb', line 51 def instance @instance ||= new end |
.register_async_source(&block) ⇒ Object
46 47 48 49 |
# File 'lib/homura/runtime/async_registry.rb', line 46 def register_async_source(&block) builder = Builder.new(instance) builder.instance_eval(&block) end |
.reset! ⇒ Object
55 56 57 |
# File 'lib/homura/runtime/async_registry.rb', line 55 def reset! @instance = new end |
.taint_return_class(class_name, method_name) ⇒ Object
67 68 69 |
# File 'lib/homura/runtime/async_registry.rb', line 67 def taint_return_class(class_name, method_name) instance.taint_return_class(class_name, method_name) end |
.tainted_class?(class_name) ⇒ Boolean
71 72 73 |
# File 'lib/homura/runtime/async_registry.rb', line 71 def tainted_class?(class_name) instance.tainted_class?(class_name) end |
Instance Method Details
#async?(class_name, method_name) ⇒ Boolean
133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/homura/runtime/async_registry.rb', line 133 def async?(class_name, method_name) return false if method_name == :new methods = @async_methods[class_name] return true if methods&.include?(method_name) except = @async_classes[class_name] if except && !except.include?(method_name.to_s) && !except.include?(method_name.to_sym) return true end false end |
#factory?(class_name, method_name) ⇒ Boolean
145 146 147 |
# File 'lib/homura/runtime/async_registry.rb', line 145 def factory?(class_name, method_name) @async_factories[class_name]&.include?(method_name) end |
#taint_return_class(class_name, method_name) ⇒ Object
149 150 151 |
# File 'lib/homura/runtime/async_registry.rb', line 149 def taint_return_class(class_name, method_name) @taint_returns[class_name]&.[](method_name) end |
#tainted_class?(class_name) ⇒ Boolean
153 154 155 156 |
# File 'lib/homura/runtime/async_registry.rb', line 153 def tainted_class?(class_name) @async_classes.key?(class_name) || @async_methods.key?(class_name) || @async_factories.key?(class_name) || @taint_returns.key?(class_name) end |