Class: BBK::App::Dispatcher::Route

Inherits:
Object
  • Object
show all
Defined in:
lib/bbk/app/dispatcher/route.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(string) ⇒ Route

Example: mq://[email protected]



11
12
13
14
15
16
17
18
19
# File 'lib/bbk/app/dispatcher/route.rb', line 11

def initialize(string)
  @uri = URI(string)
  @scheme = uri.scheme
  @domain = uri.user
  @routing_key = "#{uri.host}#{uri.path}"

  # raise 'domain must present in route' if @domain.blank?
  raise 'routing_key must present in route' if @routing_key.blank?
end

Instance Attribute Details

#domainObject (readonly)

Returns the value of attribute domain.



8
9
10
# File 'lib/bbk/app/dispatcher/route.rb', line 8

def domain
  @domain
end

#routing_keyObject (readonly)

Returns the value of attribute routing_key.



8
9
10
# File 'lib/bbk/app/dispatcher/route.rb', line 8

def routing_key
  @routing_key
end

#schemeObject (readonly)

Returns the value of attribute scheme.



8
9
10
# File 'lib/bbk/app/dispatcher/route.rb', line 8

def scheme
  @scheme
end

#uriObject (readonly)

Returns the value of attribute uri.



8
9
10
# File 'lib/bbk/app/dispatcher/route.rb', line 8

def uri
  @uri
end

Instance Method Details

#==(other) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/bbk/app/dispatcher/route.rb', line 25

def ==(other)
  if other.is_a?(String)
    to_s == other
  else
    super
  end
end

#paramsObject



33
34
35
# File 'lib/bbk/app/dispatcher/route.rb', line 33

def params
  @params ||= Hash[URI.decode_www_form(uri.query.presence || '')] 
end

#to_sObject



21
22
23
# File 'lib/bbk/app/dispatcher/route.rb', line 21

def to_s
  @uri.to_s
end