nginx-conf 0.0.1
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 +7 -0
- data/lib/nginx-conf/compiler.rb +52 -0
- data/lib/nginx-conf/conf.rb +17 -0
- data/lib/nginx-conf.rb +1 -0
- metadata +47 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6f428df41ca4fdf007279f386b1efe23ccba81eb
|
4
|
+
data.tar.gz: 045fafa381b8a44ca5b790ae1f02be08afaa9b7b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 18415d25a1ac4a365eec3a513bfee2f86787d92baf80266924889dfa3ae0f3e37ca6550412936c1f0e683e7dd841ee29757aa1e28c09118924354cf8b9766114
|
7
|
+
data.tar.gz: 05a447cf9c90681c8fdf00dcd102a2e8d12c032c1fe2ff4125f4ad393ed9a1801a35739979a7870152788adfd8c0bea6d0d385fd42b66961369e49013d2aa143
|
@@ -0,0 +1,52 @@
|
|
1
|
+
class Compiler
|
2
|
+
@@spaces = ' ' * 4
|
3
|
+
|
4
|
+
def compile hash
|
5
|
+
@indents = 0
|
6
|
+
compile_hash_without_brackets hash
|
7
|
+
end
|
8
|
+
|
9
|
+
def compile_elem object
|
10
|
+
case object
|
11
|
+
when Hash
|
12
|
+
compile_hash object
|
13
|
+
when Array
|
14
|
+
object.map{ |o| compile_elem(o) }.join(' ')
|
15
|
+
when -> (o) { o.respond_to? :to_s }
|
16
|
+
object.to_s
|
17
|
+
else
|
18
|
+
exit "You sucks!"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def compile_hash hash
|
23
|
+
s = "{\n"
|
24
|
+
@indents += 1
|
25
|
+
s += compile_hash_without_brackets hash
|
26
|
+
@indents -= 1
|
27
|
+
s + indent('}')
|
28
|
+
end
|
29
|
+
|
30
|
+
def compile_hash_without_brackets hash
|
31
|
+
hash.map do |key, values|
|
32
|
+
s = case key
|
33
|
+
when :servers
|
34
|
+
values.map do |config|
|
35
|
+
compile_hash_item :server, [config]
|
36
|
+
end.join()
|
37
|
+
else
|
38
|
+
compile_hash_item key, values
|
39
|
+
end
|
40
|
+
|
41
|
+
indent(s) + "\n"
|
42
|
+
end.join()
|
43
|
+
end
|
44
|
+
|
45
|
+
def compile_hash_item key, values
|
46
|
+
key.to_s + ' ' + compile_elem(values) + (values[-1].is_a?(Hash) ? "" : ";")
|
47
|
+
end
|
48
|
+
|
49
|
+
def indent line
|
50
|
+
@@spaces * @indents + line
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require_relative 'compiler'
|
2
|
+
|
3
|
+
|
4
|
+
class NginxConf
|
5
|
+
def initialize hash
|
6
|
+
raise unless !hash.has_key?(:http)
|
7
|
+
@hash = hash.merge({http: {servers: []}})
|
8
|
+
end
|
9
|
+
|
10
|
+
def add_server hash
|
11
|
+
@hash[:http][:servers].push(hash)
|
12
|
+
end
|
13
|
+
|
14
|
+
def compile
|
15
|
+
Compiler.new.compile(@hash)
|
16
|
+
end
|
17
|
+
end
|
data/lib/nginx-conf.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require_relative 'nginx-conf/conf'
|
metadata
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: nginx-conf
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Yota Toyama
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-10-15 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: nginx.conf generator which tries to exploit expressiveness of built-in
|
14
|
+
types
|
15
|
+
email: raviqqe@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- lib/nginx-conf.rb
|
21
|
+
- lib/nginx-conf/compiler.rb
|
22
|
+
- lib/nginx-conf/conf.rb
|
23
|
+
homepage: https://github.com/raviqqe/nginx-conf.rb
|
24
|
+
licenses:
|
25
|
+
- Unlicense
|
26
|
+
metadata: {}
|
27
|
+
post_install_message:
|
28
|
+
rdoc_options: []
|
29
|
+
require_paths:
|
30
|
+
- lib
|
31
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
32
|
+
requirements:
|
33
|
+
- - ">="
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '0'
|
36
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
requirements: []
|
42
|
+
rubyforge_project:
|
43
|
+
rubygems_version: 2.6.4
|
44
|
+
signing_key:
|
45
|
+
specification_version: 4
|
46
|
+
summary: nginx.conf generator
|
47
|
+
test_files: []
|