Module: Telemetry::AMQP::Defaults

Included in:
Base, Management
Defined in:
lib/telemetry/amqp/defaults.rb

Instance Method Summary collapse

Instance Method Details

#app_versionObject



80
81
82
# File 'lib/telemetry/amqp/defaults.rb', line 80

def app_version
  opts.key?(:app_version) ? @opts[:app_version] : Telemetry::AMQP::VERSION
end

#applicationObject



76
77
78
# File 'lib/telemetry/amqp/defaults.rb', line 76

def application
  opts.key?(:application) ? @opts[:application] : 'telemetry::amqp'
end

#connection_nameObject



84
85
86
# File 'lib/telemetry/amqp/defaults.rb', line 84

def connection_name
  opts[:connection_name] || "#{application || 'telemetry_amqp'}:#{app_version || Telemetry::AMQP::VERSION}"
end

#env_prefixObject



8
9
10
# File 'lib/telemetry/amqp/defaults.rb', line 8

def env_prefix
  @opts[:env_prefix] || 'telemetry'
end

#hostnameObject



12
13
14
15
16
17
18
19
20
# File 'lib/telemetry/amqp/defaults.rb', line 12

def hostname
  @hostname ||= if opts.key? :hostname
                  opts[:hostname]
                elsif ENV.key? "#{env_prefix}_amqp_hostname"
                  ENV["#{env_prefix}_amqp_hostname"]
                else
                  socket_hostname
                end
end

#nodesObject



88
89
90
# File 'lib/telemetry/amqp/defaults.rb', line 88

def nodes
  opts[:nodes]
end

#optsObject



92
93
94
# File 'lib/telemetry/amqp/defaults.rb', line 92

def opts
  @opts ||= {}
end

#passwordObject



32
33
34
35
36
37
38
39
40
# File 'lib/telemetry/amqp/defaults.rb', line 32

def password
  @password ||= if opts.key? :password
                  opts[:password]
                elsif ENV.key? "#{env_prefix}_amqp_password"
                  ENV["#{env_prefix}_amqp_password"]
                else
                  'guest'
                end
end

#portObject



64
65
66
67
68
69
70
71
72
73
74
# File 'lib/telemetry/amqp/defaults.rb', line 64

def port
  @port ||= if opts.key? :port
              opts[:port]
            elsif ENV.key? "#{env_prefix}_amqp_port"
              ENV["#{env_prefix}_amqp_port"].to_i
            elsif use_ssl?
              5671
            else
              5672
            end
end

#socket_hostnameObject



4
5
6
# File 'lib/telemetry/amqp/defaults.rb', line 4

def socket_hostname
  Socket.gethostname.delete_suffix('.').downcase
end

#use_ssl?Boolean

Returns:

  • (Boolean)


52
53
54
55
56
57
58
59
60
61
62
# File 'lib/telemetry/amqp/defaults.rb', line 52

def use_ssl?
  @use_ssl unless @use_ssl.nil?

  @use_ssl = if opts.key? :use_ssl
               opts[:use_ssl]
             elsif ENV.key? "#{env_prefix}_amqp_use_ssl"
               ENV["#{env_prefix}_amqp_use_ssl"] == 'true' || ENV["#{env_prefix}_amqp_use_ssl"] == '1'
             else
               false
             end
end

#usernameObject



22
23
24
25
26
27
28
29
30
# File 'lib/telemetry/amqp/defaults.rb', line 22

def username
  @username ||= if opts.key? :username
                  opts[:username]
                elsif ENV.key? "#{env_prefix}_amqp_username"
                  ENV["#{env_prefix}_amqp_username"]
                else
                  'guest'
                end
end

#vhostObject



42
43
44
45
46
47
48
49
50
# File 'lib/telemetry/amqp/defaults.rb', line 42

def vhost
  @vhost ||= if opts.key? :vhost
               opts[:vhost]
             elsif ENV.key? "#{env_prefix}_amqp_vhost"
               ENV["#{env_prefix}_amqp_vhost"]
             else
               'telemetry'
             end
end