Class: Spikard::Provide
- Inherits:
-
Object
- Object
- Spikard::Provide
- Defined in:
- lib/spikard/provide.rb
Overview
Wrapper class for dependency providers
This class wraps factory functions and configuration for dependency injection. It provides a consistent API across Python, Node.js, and Ruby bindings.
Instance Attribute Summary collapse
-
#cacheable ⇒ Object
readonly
Returns the value of attribute cacheable.
-
#depends_on ⇒ Object
readonly
Returns the value of attribute depends_on.
-
#factory ⇒ Object
readonly
Returns the value of attribute factory.
-
#singleton ⇒ Object
readonly
Returns the value of attribute singleton.
Instance Method Summary collapse
-
#async? ⇒ Boolean
Check if the factory is async (based on method arity or other heuristics).
-
#async_generator? ⇒ Boolean
Check if the factory is an async generator.
-
#initialize(factory, depends_on: [], singleton: false, cacheable: true) ⇒ Provide
constructor
Create a new dependency provider.
Constructor Details
#initialize(factory, depends_on: [], singleton: false, cacheable: true) ⇒ Provide
Create a new dependency provider
27 28 29 30 31 32 |
# File 'lib/spikard/provide.rb', line 27 def initialize(factory, depends_on: [], singleton: false, cacheable: true) @factory = factory @depends_on = Array(depends_on).map(&:to_s) @singleton = singleton @cacheable = cacheable end |
Instance Attribute Details
#cacheable ⇒ Object (readonly)
Returns the value of attribute cacheable.
19 20 21 |
# File 'lib/spikard/provide.rb', line 19 def cacheable @cacheable end |
#depends_on ⇒ Object (readonly)
Returns the value of attribute depends_on.
19 20 21 |
# File 'lib/spikard/provide.rb', line 19 def depends_on @depends_on end |
#factory ⇒ Object (readonly)
Returns the value of attribute factory.
19 20 21 |
# File 'lib/spikard/provide.rb', line 19 def factory @factory end |
#singleton ⇒ Object (readonly)
Returns the value of attribute singleton.
19 20 21 |
# File 'lib/spikard/provide.rb', line 19 def singleton @singleton end |
Instance Method Details
#async? ⇒ Boolean
Check if the factory is async (based on method arity or other heuristics)
37 38 39 40 41 |
# File 'lib/spikard/provide.rb', line 37 def async? # Ruby doesn't have explicit async/await like Python/JS # We could check if it returns a Thread or uses Fiber false end |
#async_generator? ⇒ Boolean
Check if the factory is an async generator
46 47 48 |
# File 'lib/spikard/provide.rb', line 46 def async_generator? false end |