Class: EventStoreClient::GRPC::Commands::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/event_store_client/adapters/grpc/commands/command.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config:, **conn_options) ⇒ Command

Returns a new instance of Command.

Parameters:

Options Hash (**conn_options):

  • :host (String)
  • :port (Integer)
  • :username (String)
  • :password (String)


26
27
28
29
# File 'lib/event_store_client/adapters/grpc/commands/command.rb', line 26

def initialize(config:, **conn_options)
  @config = config
  @connection = EventStoreClient::GRPC::Connection.new(config: config, **conn_options)
end

Class Method Details

.use_request(request_klass) ⇒ Object



8
9
10
# File 'lib/event_store_client/adapters/grpc/commands/command.rb', line 8

def use_request(request_klass)
  CommandRegistrar.register_request(self, request: request_klass)
end

.use_service(service_klass) ⇒ Object



12
13
14
# File 'lib/event_store_client/adapters/grpc/commands/command.rb', line 12

def use_service(service_klass)
  CommandRegistrar.register_service(self, service: service_klass)
end

Instance Method Details

#callObject

Override it in your implementation of command.

Raises:

  • (NotImplementedError)


32
33
34
# File 'lib/event_store_client/adapters/grpc/commands/command.rb', line 32

def call
  raise NotImplementedError
end

#connection_optionsHash

Returns connection options’ hash.

Returns:

  • (Hash)

    connection options’ hash



57
58
59
# File 'lib/event_store_client/adapters/grpc/commands/command.rb', line 57

def connection_options
  @connection.options_hash
end

#metadataHash

Returns:

  • (Hash)


37
38
39
40
41
42
43
# File 'lib/event_store_client/adapters/grpc/commands/command.rb', line 37

def 
  return {} unless connection.class.secure?

  credentials =
    Base64.encode64("#{connection.username}:#{connection.password}").delete("\n")
  { 'authorization' => "Basic #{credentials}" }
end

#requestObject

Returns GRPC params class to be used in the request. E.g.EventStore::Client::Streams::ReadReq.

Returns:

  • GRPC params class to be used in the request. E.g.EventStore::Client::Streams::ReadReq



47
48
49
# File 'lib/event_store_client/adapters/grpc/commands/command.rb', line 47

def request
  CommandRegistrar.request(self.class)
end

#serviceObject

Returns GRPC request stub class. E.g. EventStore::Client::Streams::Streams::Stub.

Returns:

  • GRPC request stub class. E.g. EventStore::Client::Streams::Streams::Stub



52
53
54
# File 'lib/event_store_client/adapters/grpc/commands/command.rb', line 52

def service
  connection.call(CommandRegistrar.service(self.class))
end