Class: VhostGenerator::NginxGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/vhost_generator/nginx_generator.rb

Overview

Nginx VhostGenerator

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cfg, options = {}) ⇒ NginxGenerator

Returns a new instance of NginxGenerator.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/vhost_generator/nginx_generator.rb', line 10

def initialize(cfg, options={})
  @cfg = cfg
  @options = OpenStruct.new(default_options.merge(options))
  @options.upstream ||= cfg.application
  @options.has_upstream = cfg.instance_ports.length > 1
  @options.proxy_pass =
      if @options.has_upstream
        @options.upstream
      elsif cfg.instance_ports.length > 0
        "localhost:#{cfg.instance_ports.first}"
      else
        raise ArgumentError, "Please specify at least 1 instance-port."
      end
  @options.freeze
end

Instance Attribute Details

#cfgObject (readonly)

Returns the value of attribute cfg.



9
10
11
# File 'lib/vhost_generator/nginx_generator.rb', line 9

def cfg
  @cfg
end

#optionsObject (readonly)

Returns the value of attribute options.



9
10
11
# File 'lib/vhost_generator/nginx_generator.rb', line 9

def options
  @options
end

Instance Method Details

#renderObject



26
27
28
# File 'lib/vhost_generator/nginx_generator.rb', line 26

def render
  template.result(binding)
end