Class: Solana::Ruby::Kit::PluginClient

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/solana/ruby/kit/plugin_core.rb

Instance Method Summary collapse

Constructor Details

#initializePluginClient

Returns a new instance of PluginClient.



18
19
20
# File 'lib/solana/ruby/kit/plugin_core.rb', line 18

def initialize
  @methods = T.let({}, T::Hash[Symbol, T.proc.params(args: T.untyped).returns(T.untyped)])
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object



35
36
37
38
39
40
# File 'lib/solana/ruby/kit/plugin_core.rb', line 35

def method_missing(name, *args, &block)
  m = @methods[name]
  return super unless m

  T.unsafe(m).call(*args, &block)
end

Instance Method Details

#respond_to_missing?(name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/solana/ruby/kit/plugin_core.rb', line 43

def respond_to_missing?(name, include_private = false)
  @methods.key?(name) || super
end

#use(plugin) ⇒ Object



27
28
29
30
31
32
# File 'lib/solana/ruby/kit/plugin_core.rb', line 27

def use(plugin)
  new_methods = plugin.respond_to?(:call) ? plugin.call(self) : plugin
  extended    = PluginClient.new
  extended.instance_variable_set(:@methods, @methods.merge(new_methods.transform_keys(&:to_sym)))
  extended
end