Class: Mqlight::Service
- Inherits:
-
Object
- Object
- Mqlight::Service
- Includes:
- Logging, URI
- Defined in:
- lib/mqlight/util.rb
Overview
A contain design to hold all the connection information. Note. the ‘to_s’ has been designed to supress showing the password.
Instance Attribute Summary collapse
-
#address ⇒ Object
readonly
Returns the value of attribute address.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#pattern ⇒ Object
readonly
Returns the value of attribute pattern.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#service ⇒ Object
readonly
Returns the value of attribute service.
Instance Method Summary collapse
-
#initialize(uri, user = nil, password = nil) ⇒ Service
constructor
A new instance of Service.
-
#inspect ⇒ Object
Override inspect so that the URI passwords are not returned as clear text.
- #ssl? ⇒ Boolean
- #to_s ⇒ Object
Methods included from Logging
Constructor Details
#initialize(uri, user = nil, password = nil) ⇒ Service
Returns a new instance of Service.
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 |
# File 'lib/mqlight/util.rb', line 199 def initialize(uri, user = nil, password = nil) # No Trace - security @service_uri = uri unless @service_uri.port @service_uri.port = (@service_uri.scheme == 'amqps') ? 5671 : 5672 end # Handle authentication information. if user && password && @service_uri.userinfo.nil? @service_uri.userinfo = "#{URI.encode_www_form_component(user)}:"\ "#{URI.encode_www_form_component(password)}" end @address = @service_uri.to_s p = @service_uri.clone p.userinfo = '' @pattern = p.to_s @service = "#{@service_uri.scheme}://#{@service_uri.host}:" \ "#{@service_uri.port}" @host = @service_uri.host @port = @service_uri.port # No Trace end |
Instance Attribute Details
#address ⇒ Object (readonly)
Returns the value of attribute address.
189 190 191 |
# File 'lib/mqlight/util.rb', line 189 def address @address end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
191 192 193 |
# File 'lib/mqlight/util.rb', line 191 def host @host end |
#pattern ⇒ Object (readonly)
Returns the value of attribute pattern.
188 189 190 |
# File 'lib/mqlight/util.rb', line 188 def pattern @pattern end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
192 193 194 |
# File 'lib/mqlight/util.rb', line 192 def port @port end |
#service ⇒ Object (readonly)
Returns the value of attribute service.
190 191 192 |
# File 'lib/mqlight/util.rb', line 190 def service @service end |
Instance Method Details
#inspect ⇒ Object
Override inspect so that the URI passwords are not returned as clear text
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 |
# File 'lib/mqlight/util.rb', line 248 def inspect a = '<Mqlight::Service' a << ' @service_uri = ' a << @service_uri.inspect.sub(%r{:[^\/:]+@}, ':********@') a << ', @address = ' a << @address.inspect.sub(%r{:[^\/:]+@}, ':********@') a << ', @pattern = ' a << @pattern.inspect a << ', @service = ' a << @service.inspect a << ', @host = ' a << @host.inspect a << ', @port = ' a << @port.inspect a << '>' end |
#ssl? ⇒ Boolean
227 228 229 |
# File 'lib/mqlight/util.rb', line 227 def ssl? @service_uri.scheme == 'amqps' end |
#to_s ⇒ Object
234 235 236 237 238 239 240 241 242 |
# File 'lib/mqlight/util.rb', line 234 def to_s if @service_uri.userinfo "[Service] #{@service_uri.scheme}://#{@service_uri.user}:*******" \ "@#{@service_uri.host}:#{@service_uri.port}" else "[Service] #{@service_uri.scheme}://#{@service_uri.host}:" \ "#{@service_uri.port}" end end |