Class: OpsKit::VHost

Inherits:
Object
  • Object
show all
Defined in:
lib/opskit/vhost.rb

Constant Summary collapse

PROVIDERS =
Dir.entries( File.join( File.dirname(__FILE__), "templates/" ) ).select {|f| !File.directory? f}.map{ |e| e.split('.').first.to_sym }

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(conf = {}) ⇒ VHost

Returns a new instance of VHost.



7
8
9
# File 'lib/opskit/vhost.rb', line 7

def initialize( conf = {} )
  @conf = conf
end

Instance Attribute Details

#confObject (readonly)

Returns the value of attribute conf.



5
6
7
# File 'lib/opskit/vhost.rb', line 5

def conf
  @conf
end

Instance Method Details

#renderObject



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/opskit/vhost.rb', line 11

def render
  if PROVIDERS.include? @conf[ :template ].to_sym
    file_path = File.join( File.dirname(__FILE__), "templates/#{ @conf[ :template ] }.erb.conf" )
  elsif @conf[ :template ]
    file_path = @conf[ :template ]
  end

  template = File.read( file_path )
  vhost = Erubis::Eruby.new( template )
  vhost.result(@conf)
end

#vhost_locationObject



23
24
25
26
27
28
# File 'lib/opskit/vhost.rb', line 23

def vhost_location
  case @conf[ :template ].to_sym
  when :apache
    "/etc/apache2/sites-available/#{ @conf[:url] }.conf"
  end
end