nginx-conf 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a99c739bce2eddd662d416c4ce9bd065e823c5cd
4
- data.tar.gz: e84d843bff928badb3b8bd14ff7558fa3e685121
3
+ metadata.gz: 2113222f57826f4a385670b75ba8d1dfc9f6818b
4
+ data.tar.gz: c574ef777215010cd02131bbdbaf4aec78361006
5
5
  SHA512:
6
- metadata.gz: 614222b2838a16aea7654068bfa4811f74a9a6cad46756e08510ac08187b913efc79522c7279b701bb2659f81430310772fa9bacf32fb511f33f1b1ac7157c6e
7
- data.tar.gz: 41b44d6f134fbaeb47f8a6a28ae90081734879ec4bc02db3acad8b60f444cd048137ab94a00e2226e929141f7af124ed2593c80fdba80e606a341a9692a60bcc
6
+ metadata.gz: 08721857af181bb9cfc9b31ff2114ea725626ab8b82a4d70b08e54ef96df3a2dd13d5da2798299864ed5ae42bbe49e08782bb84eea0a651d58662d25dd97a069
7
+ data.tar.gz: 389e9ff5ce26f3d784e0b0964a0dd769b7e956ec000715be958eeb527e3a6238ef433020f0d3cb5c3464169d8ce2706fce4eb416f8db3934e1bd900c7ebfad67
data/lib/nginx-conf.rb CHANGED
@@ -1 +1 @@
1
- require_relative 'nginx-conf/conf'
1
+ require_relative 'nginx-conf/nginx_conf'
@@ -1,6 +1,10 @@
1
1
  class Compiler
2
2
  @@spaces = ' ' * 4
3
3
 
4
+ def initialize repeats
5
+ @repeats = repeats
6
+ end
7
+
4
8
  def compile hash
5
9
  @indents = 0
6
10
  compile_hash_without_brackets hash
@@ -29,8 +33,7 @@ class Compiler
29
33
 
30
34
  def compile_hash_without_brackets hash
31
35
  hash.map do |key, values|
32
- case key
33
- when :server, :load_module
36
+ if @repeats.include? key
34
37
  values.map do |config|
35
38
  compile_hash_item key, [config]
36
39
  end.join()
@@ -1,25 +1,39 @@
1
1
  require_relative 'compiler'
2
2
 
3
3
 
4
- class NginxConf
5
- def initialize hash
6
- raise if [:http, :load_module].any? { |k| hash.has_key? k }
7
- @hash = hash.merge({load_module: [], http: {server: []}})
8
- end
9
4
 
10
- def load_module path
11
- @hash[:load_module].push(path)
5
+ class Conf
6
+ def initialize repeats, &block
7
+ @repeats = repeats
8
+ @attrs = {}
9
+ instance_eval(&block)
12
10
  end
13
11
 
14
- def server hash
15
- @hash[:http][:server].push(hash)
12
+ def method_missing name, *args, &block
13
+ if not (args or block)
14
+ @attrs[name]
15
+ end
16
+
17
+ if block
18
+ args.push Conf.new(@repeats, &block).to_hash
19
+ end
20
+
21
+ value = args.length == 1 ? args[0] : args
22
+
23
+ if @repeats.include? name and @attrs.include? name
24
+ @attrs[name].push value
25
+ elsif @repeats.include? name
26
+ @attrs[name] = [value]
27
+ else
28
+ @attrs[name] = value
29
+ end
16
30
  end
17
31
 
18
- def to_s
19
- Compiler.new.compile(@hash)
32
+ def to_hash
33
+ @attrs
20
34
  end
21
35
 
22
- def [] key
23
- @hash[key]
36
+ def to_s
37
+ Compiler.new(@repeats).compile(@attrs)
24
38
  end
25
39
  end
@@ -0,0 +1,7 @@
1
+ require_relative 'conf'
2
+
3
+
4
+
5
+ def nginx_conf &block
6
+ Conf.new(%i(server load_module), &block).to_s
7
+ end
metadata CHANGED
@@ -1,17 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nginx-conf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yota Toyama
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-15 00:00:00.000000000 Z
11
+ date: 2016-10-23 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: nginx.conf generator which tries to exploit expressiveness of built-in
14
- types
13
+ description: nginx.conf generator with pretty DSL
15
14
  email: raviqqe@gmail.com
16
15
  executables: []
17
16
  extensions: []
@@ -20,6 +19,7 @@ files:
20
19
  - lib/nginx-conf.rb
21
20
  - lib/nginx-conf/compiler.rb
22
21
  - lib/nginx-conf/conf.rb
22
+ - lib/nginx-conf/nginx_conf.rb
23
23
  homepage: https://github.com/raviqqe/nginx-conf.rb
24
24
  licenses:
25
25
  - Unlicense
@@ -40,7 +40,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
40
40
  version: '0'
41
41
  requirements: []
42
42
  rubyforge_project:
43
- rubygems_version: 2.6.4
43
+ rubygems_version: 2.5.1
44
44
  signing_key:
45
45
  specification_version: 4
46
46
  summary: nginx.conf generator