Class: Ethmo::Client

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/ethmo/client.rb

Overview

:nodoc:

Constant Summary collapse

AVAILABLE_METHOD =
{
  balance_of: 'eth_getBalance',
  block_from: 'eth_getBlockByHash'
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeClient

Returns a new instance of Client.



24
25
26
27
# File 'lib/ethmo/client.rb', line 24

def initialize
  # TODO: Add support for WebSocket and others
  @conn = IPCSocket.new(Config.socket)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



33
34
35
36
37
# File 'lib/ethmo/client.rb', line 33

def method_missing(name, *args, &block)
  return super unless AVAILABLE_METHOD.keys.include?(name)
  @conn.exec(AVAILABLE_METHOD[name], *args)
  JSON.parse(@conn.read)
end

Class Method Details

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



13
14
15
16
# File 'lib/ethmo/client.rb', line 13

def method_missing(name, *args, &block)
  return super unless instance.respond_to?(name)
  instance.public_send(name, *args, &block)
end

.respond_to_missing?(*args) ⇒ Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/ethmo/client.rb', line 9

def respond_to_missing?(*args)
  instance.respond_to_missing?(*args)
end

Instance Method Details

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

Returns:

  • (Boolean)


29
30
31
# File 'lib/ethmo/client.rb', line 29

def respond_to_missing?(name, include_private = false)
  AVAILABLE_METHOD.keys.include?(name) || super
end