Class: VhostGenerator::ApacheGenerator

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

Overview

Apache VhostGenerator

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of ApacheGenerator.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/vhost_generator/apache_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
        "balancer://#{@options.upstream}"
      elsif cfg.instance_ports.length > 0
        "http://localhost:#{cfg.instance_ports.first}"
      else
        raise ArgumentError, "Please specify at least 1 instance-port."
      end
  # by commodity, support same syntax as nginx: 15d, 2m, 1y
  expires = {'d' => 'days', 'm' => 'months', 'y' => 'years'}
  @options.assets_expire_in.gsub!(/\A(\d+)([dmy])\Z/) do |_|
    [$~[1], expires.fetch($~[2])].join(' ') # s/15d/15 days/g
  end
  # by commodity, support same syntax as nginx: 2k, 2M, 2G
  sizes = {'k' => 1024, 'M' => 1024**2, 'G' => 1024**3}
  if @options.client_max_body_size =~ /\A(\d+)([kMG])\Z/
    @options.client_max_body_size = Integer($~[1]) * sizes[$~[2]] - 1
  else
    @options.client_max_body_size = Integer(@options.client_max_body_size)
  end
  # apache does not support body sizes > 2G
  if @options.client_max_body_size > (size_max = 2 * sizes['G'] - 1)
    @options.client_max_body_size = size_max
  end
  @options.freeze
end

Instance Attribute Details

#cfgObject (readonly)

Returns the value of attribute cfg.



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

def cfg
  @cfg
end

#optionsObject (readonly)

Returns the value of attribute options.



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

def options
  @options
end

Instance Method Details

#renderObject



42
43
44
# File 'lib/vhost_generator/apache_generator.rb', line 42

def render
  template.result(binding)
end