class PortMap::NginxConf
Constants
- DOMAIN
- PORT_MAP_CONF_FILENAME
- PORT_PLACEHOLDER
Attributes
domain[R]
name[R]
output[R]
port[R]
Public Class Methods
from_file(port, file)
click to toggle source
# File lib/port_map/nginx_conf.rb, line 12 def self.from_file(port, file) file_content = file.read raise "File #{file} does not contain special $PORT placeholder" unless file_content.include?(PORT_PLACEHOLDER) file_content = file_content.sub(PORT_PLACEHOLDER, port) name, domain = file_content.match(/server_name\s+(.+)\.(.+?);/).captures new(port, name, domain, file_content) end
new(port, name, domain = DOMAIN, existing_conf_content = '')
click to toggle source
# File lib/port_map/nginx_conf.rb, line 22 def initialize(port, name, domain = DOMAIN, existing_conf_content = '') @name = name @port = port @domain = domain if existing_conf_content.empty? @output = default_conf_content else @output = existing_conf_content end end
Public Instance Methods
default_conf_content()
click to toggle source
# File lib/port_map/nginx_conf.rb, line 34 def default_conf_content %( server { listen 80; server_name #{@name}.#{DOMAIN}; location / { proxy_pass http://127.0.0.1:#{@port}; } } ) end
filename()
click to toggle source
# File lib/port_map/nginx_conf.rb, line 51 def filename Nginx.servers_directory + File::Separator + @name + '.port_map.conf' end
save()
click to toggle source
# File lib/port_map/nginx_conf.rb, line 55 def save File.open(filename, 'w+') { |f| f.write(@output) } end
server_name()
click to toggle source
# File lib/port_map/nginx_conf.rb, line 47 def server_name "#{@name}.#{@domain}" end