nginxtra 1.2.3.5 → 1.2.3.6

Sign up to get free protection for your applications and to get access to all the features.
data/bin/nginxtra CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
  require "rubygems"
3
- gem "nginxtra", "= 1.2.3.5"
3
+ gem "nginxtra", "= 1.2.3.6"
4
4
  gem "thor", "~> 0.16.0"
5
5
  require "nginxtra"
6
6
  Nginxtra::CLI.start
data/bin/nginxtra_rails CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
  require "rubygems"
3
- gem "nginxtra", "= 1.2.3.5"
3
+ gem "nginxtra", "= 1.2.3.6"
4
4
  gem "thor", "~> 0.16.0"
5
5
  require "nginxtra"
6
6
  Nginxtra::Rails::CLI.start
@@ -8,11 +8,65 @@ module Nginxtra
8
8
  NGINX_PIDFILE_FILENAME = ".nginx_pid".freeze
9
9
  @@last_config = nil
10
10
 
11
- def initialize
11
+ def initialize(*args)
12
12
  @requires_root = false
13
13
  @compile_options = []
14
+ @partial_paths = []
15
+ @file_paths = []
14
16
  @files = {}
15
17
  @@last_config = self
18
+
19
+ if block_given?
20
+ yield self
21
+ end
22
+ end
23
+
24
+ # Define an additional directory where partials can be found. The
25
+ # passed in path should have directories listed by configuration
26
+ # file, then partials within those.
27
+ #
28
+ # For example:
29
+ # custom_partials "/my/path"
30
+ # /my/path/nginx.conf/rails.rb
31
+ # /my/path/nginx.conf/static.rb
32
+ def custom_partials(path)
33
+ @partial_paths << path
34
+ end
35
+
36
+ # Define an additional directory where file templates can be
37
+ # found. The passed in path should have file templates within it.
38
+ #
39
+ # For example:
40
+ # custom_files "/my/path"
41
+ # /my/path/nginx.conf.rb
42
+ def custom_files(path)
43
+ @file_paths << path
44
+ end
45
+
46
+ # Retrieve an array of directories where partials can be
47
+ # contained. This includes the custom partial directories added
48
+ # with the "custom_partials" method, in the order they were added,
49
+ # then the standard override location, and finally the standard
50
+ # gem partials.
51
+ def partial_paths
52
+ [].tap do |result|
53
+ result.push *@partial_paths
54
+ result.push File.join(Nginxtra::Config.template_dir, "partials")
55
+ result.push File.join(Nginxtra::Config.gem_template_dir, "partials")
56
+ end
57
+ end
58
+
59
+ # Retrieve an array of directories where file templates can be
60
+ # contained. This includes the custom file directories added with
61
+ # the "custom_files" method, in the order they were added, then
62
+ # the standard override location, and finally the standard gem
63
+ # file templates.
64
+ def file_paths
65
+ [].tap do |result|
66
+ result.push *@file_paths
67
+ result.push File.join(Nginxtra::Config.template_dir, "files")
68
+ result.push File.join(Nginxtra::Config.gem_template_dir, "files")
69
+ end
16
70
  end
17
71
 
18
72
  # This method is used to configure nginx via nginxtra. Inside
@@ -396,11 +450,14 @@ module Nginxtra
396
450
 
397
451
  # Process the simple config.
398
452
  def process!
399
- gem_files = find_config_files! File.join(Nginxtra::Config.gem_template_dir, "files")
400
- override_files = find_config_files! File.join(Nginxtra::Config.template_dir, "files")
453
+ file_options = @config.file_paths.map do |path|
454
+ find_config_files! path
455
+ end
401
456
 
402
- config_files = (gem_files.keys + override_files.keys).uniq.map do |x|
403
- override_files[x] || gem_files[x]
457
+ config_files = file_options.map(&:keys).inject([], &:+).uniq.map do |x|
458
+ file_options.select do |option|
459
+ option.include? x
460
+ end.first[x]
404
461
  end
405
462
 
406
463
  process_files! config_files
@@ -433,22 +490,23 @@ module Nginxtra
433
490
  files.each do |x|
434
491
  path = x[:path]
435
492
  file_name = x[:config_file]
493
+ config = @config
436
494
  options = @options
437
495
  invoked_partials = @invoked_partials
438
496
 
439
497
  yielder = proc do
440
498
  invoked_partials.each do |partial|
441
499
  method, args, block = partial
442
- partial_end_path = "partials/#{file_name}/#{method}.rb"
443
- partial_path = File.join Nginxtra::Config.gem_template_dir, partial_end_path
444
- override_partial_path = File.join Nginxtra::Config.template_dir, partial_end_path
445
500
  partial_options = {}
446
501
  partial_options = args.first if args.length > 0 && args.first.kind_of?(Hash)
447
502
 
448
- if File.exists? override_partial_path
449
- process_template! override_partial_path, partial_options, block
450
- elsif File.exists? partial_path
451
- process_template! partial_path, partial_options, block
503
+ config.partial_paths.each do |path|
504
+ partial_path = File.join path, "#{file_name}/#{method}.rb"
505
+
506
+ if File.exists? partial_path
507
+ process_template! partial_path, partial_options, block
508
+ break
509
+ end
452
510
  end
453
511
  end
454
512
  end
@@ -503,6 +561,6 @@ end
503
561
  # nginxtra.config do
504
562
  # ...
505
563
  # end
506
- def nginxtra
507
- Nginxtra::Config.new
564
+ def nginxtra(*args, &block)
565
+ Nginxtra::Config.new *args, &block
508
566
  end
@@ -2,7 +2,7 @@ module Nginxtra
2
2
  class Version
3
3
  class << self
4
4
  def to_s
5
- "1.2.3.5"
5
+ "1.2.3.6"
6
6
  end
7
7
  end
8
8
  end
@@ -1,3 +1,5 @@
1
+ run_as_user = yield :run_as
2
+ user run_as_user if run_as_user
1
3
  worker_processes(yield(:worker_processes) || 1)
2
4
 
3
5
  events do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nginxtra
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.3.5
4
+ version: 1.2.3.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-30 00:00:00.000000000 Z
12
+ date: 2012-09-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thor
16
- requirement: &7830800 !ruby/object:Gem::Requirement
16
+ requirement: &15893000 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: 0.16.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *7830800
24
+ version_requirements: *15893000
25
25
  description: This gem is intended to provide an easy to use configuration file that
26
26
  will automatically be used to compile nginx and configure the configuration.
27
27
  email: reasonnumber@gmail.com