ruby-nginx 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/ruby/nginx/commands/add_nginx_config.rb +24 -2
- data/lib/ruby/nginx/commands/remove_nginx_config.rb +19 -2
- data/lib/ruby/nginx/system/nginx.rb +2 -2
- data/lib/ruby/nginx/system/safe_file.rb +7 -7
- data/lib/ruby/nginx/version.rb +1 -1
- data/lib/ruby/nginx.rb +6 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f05254d3fb1670cd6c832b3d0cff71f7f4d04483c004de96b6ee94917a0bfc8f
|
4
|
+
data.tar.gz: 4b22e857122735828aea9ab8a506dc2c4d60d8a65caa8893b1810fba70cb3dd4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 18ddfaf53cce1326a30c8741ba22773ac0ecc78a336ae4c3418c388345dbea7ff9c62255954a63a336383a55fbdee061a2781995debd90b05b2d4707c8b32851
|
7
|
+
data.tar.gz: f42671b12a2ad714dfd698e14cb43738b880903cdaf5cc730131bac5d973e93a81012d2b8334c231e151d0b687f04cdf36cf7b7ea695e4c7e88e3c4fc391029e
|
@@ -9,8 +9,30 @@ module Ruby
|
|
9
9
|
class AddNginxConfig
|
10
10
|
include Ruby::Nginx::Constants
|
11
11
|
|
12
|
-
def
|
13
|
-
|
12
|
+
def initialize(name, config)
|
13
|
+
@name = name
|
14
|
+
@config = config
|
15
|
+
end
|
16
|
+
|
17
|
+
def run
|
18
|
+
return false unless changed?
|
19
|
+
|
20
|
+
Ruby::Nginx::System::SafeFile.write(config_path, @config)
|
21
|
+
true
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def changed?
|
27
|
+
!Ruby::Nginx::System::SafeFile.exist?(config_path) || (nginx_config != @config)
|
28
|
+
end
|
29
|
+
|
30
|
+
def config_path
|
31
|
+
@config_path ||= "#{SERVERS_PATH}/#{@name}.conf"
|
32
|
+
end
|
33
|
+
|
34
|
+
def nginx_config
|
35
|
+
@nginx_config ||= Ruby::Nginx::System::SafeFile.read(config_path)
|
14
36
|
end
|
15
37
|
end
|
16
38
|
end
|
@@ -9,8 +9,25 @@ module Ruby
|
|
9
9
|
class RemoveNginxConfig
|
10
10
|
include Ruby::Nginx::Constants
|
11
11
|
|
12
|
-
def
|
13
|
-
|
12
|
+
def initialize(name)
|
13
|
+
@name = name
|
14
|
+
end
|
15
|
+
|
16
|
+
def run
|
17
|
+
return false unless exists?
|
18
|
+
|
19
|
+
Ruby::Nginx::System::SafeFile.rm(config_path)
|
20
|
+
true
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def exists?
|
26
|
+
Ruby::Nginx::System::SafeFile.exist?(config_path)
|
27
|
+
end
|
28
|
+
|
29
|
+
def config_path
|
30
|
+
@config_path ||= "#{SERVERS_PATH}/#{@name}.conf"
|
14
31
|
end
|
15
32
|
end
|
16
33
|
end
|
@@ -32,11 +32,11 @@ module Ruby
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def add_server_config(name, config)
|
35
|
-
Commands::AddNginxConfig.new
|
35
|
+
Commands::AddNginxConfig.new(name, config).run
|
36
36
|
end
|
37
37
|
|
38
38
|
def remove_server_config(name)
|
39
|
-
Commands::RemoveNginxConfig.new
|
39
|
+
Commands::RemoveNginxConfig.new(name).run
|
40
40
|
end
|
41
41
|
|
42
42
|
def validate_config!
|
@@ -10,11 +10,15 @@ module Ruby
|
|
10
10
|
def mkdir(dir_path)
|
11
11
|
safe_path = File.expand_path(dir_path)
|
12
12
|
|
13
|
-
FileUtils.mkdir_p(
|
13
|
+
FileUtils.mkdir_p(safe_path)
|
14
14
|
|
15
15
|
safe_path
|
16
16
|
end
|
17
17
|
|
18
|
+
def exist?(file_path)
|
19
|
+
File.exist?(File.expand_path(file_path))
|
20
|
+
end
|
21
|
+
|
18
22
|
def touch(file_path)
|
19
23
|
safe_path = File.expand_path(file_path)
|
20
24
|
|
@@ -25,9 +29,7 @@ module Ruby
|
|
25
29
|
end
|
26
30
|
|
27
31
|
def read(file_path)
|
28
|
-
|
29
|
-
|
30
|
-
File.read(safe_path)
|
32
|
+
File.read(File.expand_path(file_path))
|
31
33
|
end
|
32
34
|
|
33
35
|
def write(file_path, content)
|
@@ -39,9 +41,7 @@ module Ruby
|
|
39
41
|
end
|
40
42
|
|
41
43
|
def rm(file_path)
|
42
|
-
|
43
|
-
|
44
|
-
FileUtils.rm_f(safe_path)
|
44
|
+
FileUtils.rm_f(File.expand_path(file_path))
|
45
45
|
end
|
46
46
|
end
|
47
47
|
end
|
data/lib/ruby/nginx/version.rb
CHANGED
data/lib/ruby/nginx.rb
CHANGED
@@ -14,9 +14,11 @@ module Ruby
|
|
14
14
|
setup!
|
15
15
|
conf = config(options, &block)
|
16
16
|
|
17
|
-
System::Nginx.add_server_config(conf.name, conf.generate!)
|
18
|
-
|
19
|
-
|
17
|
+
if System::Nginx.add_server_config(conf.name, conf.generate!)
|
18
|
+
System::Nginx.validate_config!
|
19
|
+
System::Nginx.restart!
|
20
|
+
end
|
21
|
+
|
20
22
|
System::Hosts.add(conf.domain, conf.host)
|
21
23
|
|
22
24
|
conf
|
@@ -30,8 +32,7 @@ module Ruby
|
|
30
32
|
def self.remove!(options = {}, &block)
|
31
33
|
conf = config(options, &block)
|
32
34
|
|
33
|
-
System::Nginx.remove_server_config(conf.name)
|
34
|
-
System::Nginx.restart!
|
35
|
+
System::Nginx.restart! if System::Nginx.remove_server_config(conf.name)
|
35
36
|
System::Hosts.remove(conf.domain)
|
36
37
|
|
37
38
|
conf
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-nginx
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bert McCutchen
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-
|
11
|
+
date: 2025-04-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: erb
|