Class: JetstreamBridge::Core::ConnectionFactory::ConnectionOptions

Inherits:
Object
  • Object
show all
Defined in:
lib/jetstream_bridge/core/connection_factory.rb

Overview

Connection options builder

Constant Summary collapse

DEFAULT_OPTS =
{
  reconnect: true,
  reconnect_time_wait: 2,
  max_reconnect_attempts: 10,
  connect_timeout: 5
}.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(servers: nil, **opts) ⇒ ConnectionOptions



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/jetstream_bridge/core/connection_factory.rb', line 24

def initialize(servers: nil, **opts)
  @servers = normalize_servers(servers) if servers
  @additional_opts = {}

  DEFAULT_OPTS.merge(opts).each do |key, value|
    if respond_to?(:"#{key}=")
      send(:"#{key}=", value)
    else
      @additional_opts[key] = value
    end
  end
end

Instance Attribute Details

#additional_optsObject (readonly)

Returns the value of attribute additional_opts.



22
23
24
# File 'lib/jetstream_bridge/core/connection_factory.rb', line 22

def additional_opts
  @additional_opts
end

#connect_timeoutObject

Returns the value of attribute connect_timeout.



19
20
21
# File 'lib/jetstream_bridge/core/connection_factory.rb', line 19

def connect_timeout
  @connect_timeout
end

#max_reconnect_attemptsObject

Returns the value of attribute max_reconnect_attempts.



19
20
21
# File 'lib/jetstream_bridge/core/connection_factory.rb', line 19

def max_reconnect_attempts
  @max_reconnect_attempts
end

#nameObject

Returns the value of attribute name.



19
20
21
# File 'lib/jetstream_bridge/core/connection_factory.rb', line 19

def name
  @name
end

#passObject

Returns the value of attribute pass.



19
20
21
# File 'lib/jetstream_bridge/core/connection_factory.rb', line 19

def pass
  @pass
end

#reconnectObject

Returns the value of attribute reconnect.



19
20
21
# File 'lib/jetstream_bridge/core/connection_factory.rb', line 19

def reconnect
  @reconnect
end

#reconnect_time_waitObject

Returns the value of attribute reconnect_time_wait.



19
20
21
# File 'lib/jetstream_bridge/core/connection_factory.rb', line 19

def reconnect_time_wait
  @reconnect_time_wait
end

#serversObject

Returns the value of attribute servers.



19
20
21
# File 'lib/jetstream_bridge/core/connection_factory.rb', line 19

def servers
  @servers
end

#tokenObject

Returns the value of attribute token.



19
20
21
# File 'lib/jetstream_bridge/core/connection_factory.rb', line 19

def token
  @token
end

#userObject

Returns the value of attribute user.



19
20
21
# File 'lib/jetstream_bridge/core/connection_factory.rb', line 19

def user
  @user
end

Class Method Details

.build(opts = {}) ⇒ Object



37
38
39
# File 'lib/jetstream_bridge/core/connection_factory.rb', line 37

def self.build(opts = {})
  new(**opts)
end

Instance Method Details

#to_hObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/jetstream_bridge/core/connection_factory.rb', line 41

def to_h
  base = {
    reconnect: @reconnect,
    reconnect_time_wait: @reconnect_time_wait,
    max_reconnect_attempts: @max_reconnect_attempts,
    connect_timeout: @connect_timeout
  }

  base[:servers] = @servers if @servers
  base[:name] = @name if @name
  base[:user] = @user if @user
  base[:pass] = @pass if @pass
  base[:token] = @token if @token

  base.merge(@additional_opts)
end