Class: ApacheVhostsParser::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/apache-vhosts-parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tag) ⇒ Config

Returns a new instance of Config.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/apache-vhosts-parser.rb', line 7

def initialize tag
	@tag = tag

	@vhosts = @tag[:children].keep_if do |child|
		child[:name] == 'virtualhost'
	end.each do |vhost|

		vhost[:addresses] = vhost[:arguments].map do |hp|
			host, port = hp.split(':')
			{
				host: host,
				port: port ? port.to_i : nil
			}
		end

		(vhost[:children] || []).each do |nested|
			if nested[:type] == 'directive'
				case nested[:name]
				when 'servername'
					vhost[:server_name] = nested[:arguments].first
				when 'documentroot'
					vhost[:document_root] = nested[:arguments].first
				end
			end
		end
	end
end

Instance Attribute Details

#vhostsObject (readonly)

Returns the value of attribute vhosts.



4
5
6
# File 'lib/apache-vhosts-parser.rb', line 4

def vhosts
  @vhosts
end

Instance Method Details

#urlFor(dir) ⇒ Object



35
36
37
38
39
40
41
42
# File 'lib/apache-vhosts-parser.rb', line 35

def urlFor dir
	vhosts.each do |h|
		if h[:document_root] == dir
			return h[:server_name]
		end
	end
	return nil
end