Class: Hubert::Components

Inherits:
Object
  • Object
show all
Defined in:
lib/hubert/components.rb

Constant Summary collapse

DEFAULT_PORTS =
{ 'http' => '80', 'https' => '443' }

Instance Method Summary collapse

Instance Method Details

#default_port?Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/hubert/components.rb', line 60

def default_port?
  DEFAULT_PORTS.fetch(protocol) == port
end

#hostObject



35
36
37
# File 'lib/hubert/components.rb', line 35

def host
  @host
end

#host=(host) ⇒ Object



29
30
31
32
33
# File 'lib/hubert/components.rb', line 29

def host=(host)
  host.strip!
  host = 'http://' + host if URI.parse(host).scheme.nil?
  @host = URI.parse(host).host
end

#http!Object



21
22
23
# File 'lib/hubert/components.rb', line 21

def http!
  @protocol = 'http'
end

#https!Object



25
26
27
# File 'lib/hubert/components.rb', line 25

def https!
  @protocol = 'https'
end

#path_prefixObject



48
49
50
# File 'lib/hubert/components.rb', line 48

def path_prefix
  @path_prefix ||= ''
end

#path_prefix=(path) ⇒ Object



39
40
41
42
43
44
45
46
# File 'lib/hubert/components.rb', line 39

def path_prefix=(path)
  path.strip!
  path = URI.parse(path).path
  path = path[0..-2] if path.end_with?('/')
  path = path[1..-1] if path.start_with?('/')

  @path_prefix = '/' + path
end

#portObject



52
53
54
# File 'lib/hubert/components.rb', line 52

def port
  @port ||= DEFAULT_PORTS.fetch(protocol, '80')
end

#port=(port) ⇒ Object



56
57
58
# File 'lib/hubert/components.rb', line 56

def port=(port)
  @port = port.to_s
end

#protocolObject



17
18
19
# File 'lib/hubert/components.rb', line 17

def protocol
  @protocol ||= 'http'
end

#protocol=(protocol) ⇒ Object



7
8
9
10
11
12
13
14
15
# File 'lib/hubert/components.rb', line 7

def protocol=(protocol)
  protocol = protocol.to_s unless protocol.is_a?(String)
  protocol.strip!
  if protocol =~ /(http)|(https)/i
    @protocol = protocol.downcase
  else
    fail InvalidProtocol, "Provided protocol: [#{protocol}] is invalid"
  end
end