Class: Ruby::Nginx::Configuration
- Inherits:
-
Object
- Object
- Ruby::Nginx::Configuration
show all
- Includes:
- Constants
- Defined in:
- lib/ruby/nginx/configuration.rb
Constant Summary
Constants included
from Constants
Ruby::Nginx::Constants::CONFIG_PATH, Ruby::Nginx::Constants::SERVERS_PATH
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(options = {}) ⇒ Configuration
Returns a new instance of Configuration.
16
17
18
|
# File 'lib/ruby/nginx/configuration.rb', line 16
def initialize(options = {})
@options = defaults.merge(options)
end
|
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
14
15
16
|
# File 'lib/ruby/nginx/configuration.rb', line 14
def options
@options
end
|
Instance Method Details
#default_paths ⇒ Object
53
54
55
56
57
58
59
60
61
|
# File 'lib/ruby/nginx/configuration.rb', line 53
def default_paths
{
temp_path: default_path("tmp"),
ssl_certificate_path: default_path("certs/_#{options[:domain]}.pem"),
ssl_certificate_key_path: default_path("certs/_#{options[:domain]}-key.pem"),
access_log_path: default_path("logs/#{options[:domain]}.access.log"),
error_log_path: default_path("logs/#{options[:domain]}.error.log")
}
end
|
#defaults ⇒ Object
43
44
45
46
47
48
49
50
51
|
# File 'lib/ruby/nginx/configuration.rb', line 43
def defaults
{
host: "127.0.0.1",
root_path: Dir.pwd,
template_path: File.expand_path("templates/nginx.conf.erb", __dir__),
ssl: false,
log: false
}
end
|
#domain ⇒ Object
20
21
22
|
# File 'lib/ruby/nginx/configuration.rb', line 20
def domain
options[:domain]
end
|
#generate! ⇒ Object
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/ruby/nginx/configuration.rb', line 32
def generate!
validate!
apply_dynamic_defaults!
create_temp_path!
create_ssl_certs! if options[:ssl]
create_log_files! if options[:log]
ERB.new(load_template).result(binding)
end
|
#host ⇒ Object
24
25
26
|
# File 'lib/ruby/nginx/configuration.rb', line 24
def host
options[:host]
end
|
#name ⇒ Object
28
29
30
|
# File 'lib/ruby/nginx/configuration.rb', line 28
def name
"ruby_nginx_#{options[:domain].gsub(/\W/, "_")}"
end
|
#nginx_version ⇒ Object
63
64
65
|
# File 'lib/ruby/nginx/configuration.rb', line 63
def nginx_version
@nginx_version ||= System::Nginx.version
end
|