Class: QuicknodeSdk::NativeDelegator
- Inherits:
-
Object
- Object
- QuicknodeSdk::NativeDelegator
- Defined in:
- lib/quicknode_sdk/native_delegator.rb
Overview
Shared base class for the user-facing client wrappers (Admin, Streams, Webhooks, KvStore). Each Magnus-bound native client is held in @native and all method calls are forwarded through method_missing.
The native side exposes two kinds of methods: arity-0 (e.g. list_chains) and arity-1 taking a single positional Hash of options (e.g. get_endpoints). To support all three Ruby call styles documented in the README and examples — bare (qn.admin.get_endpoints), kwargs (qn.admin.get_endpoints(limit: 5)), and positional hash (qn.streams.list_streams({})) — we coerce whatever the caller passed into a single options hash, then dispatch on the native arity. Arity-0 methods reject any argument (Magnus enforces this), so we must call them with no args; arity-1 methods always need a Hash passed POSITIONALLY (Magnus’s RHash is a positional arg, and Ruby 3 treats ‘**{}` as zero arguments —so we must not splat the options).
Instance Method Summary collapse
-
#initialize(native) ⇒ NativeDelegator
constructor
A new instance of NativeDelegator.
- #method_missing(name, *args, **kwargs) ⇒ Object
- #respond_to_missing?(name, include_private = false) ⇒ Boolean
Constructor Details
#initialize(native) ⇒ NativeDelegator
Returns a new instance of NativeDelegator.
18 19 20 |
# File 'lib/quicknode_sdk/native_delegator.rb', line 18 def initialize(native) @native = native end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, **kwargs) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/quicknode_sdk/native_delegator.rb', line 22 def method_missing(name, *args, **kwargs) return super unless @native.respond_to?(name) opts = if !kwargs.empty? kwargs elsif args.length == 1 && args[0].is_a?(Hash) args[0] else {} end result = if @native.method(name).arity == 0 @native.public_send(name) else @native.public_send(name, opts) end QuicknodeSdk.wrap(result) end |
Instance Method Details
#respond_to_missing?(name, include_private = false) ⇒ Boolean
39 40 41 |
# File 'lib/quicknode_sdk/native_delegator.rb', line 39 def respond_to_missing?(name, include_private = false) @native.respond_to?(name, include_private) || super end |