Class: EventStore::HTTP::Connect

Inherits:
Object
  • Object
show all
Includes:
Log::Dependency
Defined in:
lib/event_store/http/connect.rb,
lib/event_store/http/connect/leader.rb,
lib/event_store/http/connect/defaults.rb

Defined Under Namespace

Modules: Defaults, Leader

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.build(settings = nil, namespace: nil) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/event_store/http/connect.rb', line 19

def self.build(settings=nil, namespace: nil)
  settings ||= Settings.instance
  namespace ||= Array(namespace)

  instance = new
  settings.set instance, namespace
  instance
end

.call(ip_address = nil, settings: nil, namespace: nil) ⇒ Object



28
29
30
31
# File 'lib/event_store/http/connect.rb', line 28

def self.call(ip_address=nil, settings: nil, namespace: nil)
  instance = build settings, namespace: namespace
  instance.(ip_address)
end

.configure_connection(receiver, settings = nil, connection: nil, attr_name: nil, **arguments) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/event_store/http/connect.rb', line 33

def self.configure_connection(receiver, settings=nil, connection: nil, attr_name: nil, **arguments)
  attr_name ||= :connection

  connection ||= self.(settings: settings, **arguments)
  receiver.public_send "#{attr_name}=", connection
  connection
end

Instance Method Details

#call(ip_address = nil) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/event_store/http/connect.rb', line 41

def call(ip_address=nil)
  if ip_address.nil?
    connect
  else
    raw ip_address
  end
end

#connectObject



49
50
51
# File 'lib/event_store/http/connect.rb', line 49

def connect
  raw host
end

#portObject



15
16
17
# File 'lib/event_store/http/connect.rb', line 15

def port
  @port ||= Defaults.port
end

#raw(ip_address) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/event_store/http/connect.rb', line 53

def raw(ip_address)
  logger.trace { "Building Net::HTTP connection (IPAddress: #{ip_address}, Port: #{port})" }

  net_http = Net::HTTP.new ip_address, port
  net_http.keep_alive_timeout = keep_alive_timeout unless keep_alive_timeout.nil?
  net_http.open_timeout = open_timeout unless open_timeout.nil?
  net_http.read_timeout = read_timeout unless read_timeout.nil?

  logger.debug { "Net::HTTP connection built (IPAddress: #{ip_address}, Port: #{port})" }

  net_http.extend NetHTTP::Extensions

  net_http
end