nginxtra 1.8.0.11 → 1.8.1.12

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: ca12f5a209d5ce4786a62949d3d7c008eff95ddb
4
- data.tar.gz: 3c2cc4e4ba9512ba14a7f826fc34a531392c4d58
3
+ metadata.gz: 99f107b601dfcabd1f825d8f14aad06edd048f55
4
+ data.tar.gz: 824ea02e092be12cf8f22f39a1cf21a867494034
5
5
  SHA512:
6
- metadata.gz: 01a24bbabfcc70c7b6b2d5a1a92edc16c800e1dcb7e9df13ff853b4c25e10beb3a54d0e11ffe299b8758bf2a811b105431111bc15bdd8b6310a8ef2c2f32d269
7
- data.tar.gz: 0d2d617b91b6ec4df08cbe0e8cf116be72d0a385c1242260cdd7e5a8d68958f864851abe0ea63a63aaa08d3aef48489863c00110cd3dabd3792d39cd138be239
6
+ metadata.gz: e67268dddd754316d87fab9a51a2ce94884fbe801ffa4e95ffd4784ca86db5548428219682b0f8e79936dddd1ffcef803cc8acfff0d551f6582a5dc235076408
7
+ data.tar.gz: 124f0029c2f3fbac24f1882e9c894c804ea4a808f98c44b3450aeba39a398f02c1fcb831e6298a74b758424fd32f4409b0373fb5dafd746db777b27b953ceb48
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
  require "rubygems"
3
- gem "nginxtra", "= 1.8.0.11"
3
+ gem "nginxtra", "= 1.8.1.12"
4
4
  gem "thor", "~> 0.16"
5
5
  require "nginxtra"
6
6
  Nginxtra::CLI.start
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
  require "rubygems"
3
- gem "nginxtra", "= 1.8.0.11"
3
+ gem "nginxtra", "= 1.8.1.12"
4
4
  gem "thor", "~> 0.16"
5
5
  require "nginxtra"
6
6
  Nginxtra::Rails::CLI.start
@@ -1,7 +1,5 @@
1
1
  module Nginxtra
2
2
  module Action
3
- @@ignore_force = false
4
-
5
3
  def initialize(thor, config)
6
4
  @thor = thor
7
5
  @config = config
@@ -14,20 +12,21 @@ module Nginxtra
14
12
  end
15
13
 
16
14
  private
15
+
17
16
  def run!(command)
18
17
  @thor.run command
19
- raise Nginxtra::Error::RunFailed.new("The last run command failed") unless $?.success?
18
+ raise Nginxtra::Error::RunFailed, "The last run command failed" unless $?.success? # rubocop:disable Style/SpecialGlobalVars
20
19
  end
21
20
 
22
21
  def without_force
23
- @@ignore_force = true
22
+ Nginxtra::Action.ignore_force = true
24
23
  yield
25
24
  ensure
26
- @@ignore_force = false
25
+ Nginxtra::Action.ignore_force = false
27
26
  end
28
27
 
29
28
  def force?
30
- return false if @@ignore_force
29
+ return false if Nginxtra::Action.ignore_force
31
30
  @thor.options["force"]
32
31
  end
33
32
 
@@ -42,5 +41,9 @@ module Nginxtra
42
41
  def sudo(force = false)
43
42
  "sudo " if (force || (@config && @config.require_root?)) && Process.uid != 0
44
43
  end
44
+
45
+ class << self
46
+ attr_accessor :ignore_force
47
+ end
45
48
  end
46
49
  end
@@ -8,13 +8,14 @@ module Nginxtra
8
8
  def convert
9
9
  @streams_to_close = []
10
10
  converter = Nginxtra::ConfigConverter.new output
11
- converter.convert :config => config, :binary_status => binary_status
11
+ converter.convert config: config, binary_status: binary_status
12
12
  save_if_necessary!
13
13
  ensure
14
14
  close_streams!
15
15
  end
16
16
 
17
17
  private
18
+
18
19
  def output
19
20
  if @thor.options["output"]
20
21
  STDOUT
@@ -43,24 +44,24 @@ module Nginxtra
43
44
  def binary_status
44
45
  return if @thor.options["ignore-nginx-bin"]
45
46
 
46
- if @thor.options["nginx-bin"]
47
- binary = @thor.options["nginx-bin"]
48
- else
49
- binary = etc_nginx_binary
50
- end
47
+ binary = if @thor.options["nginx-bin"]
48
+ @thor.options["nginx-bin"]
49
+ else
50
+ etc_nginx_binary
51
+ end
51
52
 
52
- @thor.run "#{binary} -V 2>&1", :capture => true
53
+ @thor.run "#{binary} -V 2>&1", capture: true
53
54
  end
54
55
 
55
56
  def etc_nginx_binary
56
- raise Nginxtra::Error::ConvertFailed.new("Cannot find nginx binary", :header => "Cannot find nginx binary!", :message => "Either point to it via --nginx-bin or ignore the binary with --ignore-nginx-bin") unless File.exists? "/etc/init.d/nginx"
57
+ raise Nginxtra::Error::NginxInitScriptMissing unless File.exist? "/etc/init.d/nginx"
57
58
  binary = File.read("/etc/init.d/nginx")[/\s*DAEMON\s*=\s*(.*?)\s*$/, 1]
58
- raise Nginxtra::Error::ConvertFailed.new("Cannot determine nginx binary", :header => "Cannot find nginx binary!", :message => "The binary location of nginx cannot be determined from /etc/init.d/nginx. Either point to it via --nginx-bin or ignore the binary with --ignore-nginx-bin") unless binary
59
+ raise Nginxtra::Error::UndeterminedNginxBinary unless binary
59
60
  binary
60
61
  end
61
62
 
62
63
  def open_file(path)
63
- raise Nginxtra::Error::ConvertFailed.new("Missing config file #{path}") unless File.exists? path
64
+ raise Nginxtra::Error::ConvertFailed, "Missing config file #{path}" unless File.exist? path
64
65
 
65
66
  File.open(path, "r").tap do |stream|
66
67
  @streams_to_close << stream
@@ -68,7 +69,7 @@ module Nginxtra
68
69
  end
69
70
 
70
71
  def close_streams!
71
- @streams_to_close.each &:close
72
+ @streams_to_close.each(&:close)
72
73
  end
73
74
  end
74
75
  end
@@ -17,25 +17,26 @@ module Nginxtra
17
17
  # Look for nginx installation and fail if it exists (unless
18
18
  # --ignore-nginx-check is passed).
19
19
  def check_if_nginx_is_installed
20
- return unless File.exists?("/etc/init.d/nginx")
20
+ return unless File.exist?("/etc/init.d/nginx")
21
21
 
22
22
  if @thor.options["ignore-nginx-check"]
23
23
  @thor.say @thor.set_color("Detected nginx install, but ignoring!", :red, true)
24
24
  return
25
25
  end
26
26
 
27
- raise Nginxtra::Error::NginxDetected.new("Uninstall nginx before installing nginxtra", :header => "It appears nginx is already installed!", :message => "Since /etc/init.d/nginx exists, you might have an existing nginx installation that will conflict with nginxtra. If you want to install nginxtra alongside nginx (at your own risk), please include the --ignore-nginx-check option to bypass this check.")
27
+ raise Nginxtra::Error::NginxDetected
28
28
  end
29
29
 
30
30
  # Create a script in the base directory which be symlinked to
31
31
  # /etc/init.d/nginxtra and then used to start and stop nginxtra
32
32
  # via update-rc.d.
33
+ # rubocop:disable Metrics/AbcSize, Metrics/LineLength
33
34
  def create_etc_script
34
35
  filename = "etc.init.d.nginxtra"
35
36
  workingdir = File.expand_path "."
36
37
 
37
38
  @thor.inside Nginxtra::Config.base_dir do
38
- @thor.create_file filename, %{#!/bin/sh
39
+ @thor.create_file filename, %(#!/bin/sh
39
40
 
40
41
  ### BEGIN INIT INFO
41
42
  # Provides: nginxtra
@@ -50,14 +51,15 @@ module Nginxtra
50
51
  export GEM_HOME="#{ENV["GEM_HOME"]}"
51
52
  export GEM_PATH="#{ENV["GEM_PATH"]}"
52
53
  #{Nginxtra::Config.ruby_path} "#{File.join Nginxtra::Config.gem_dir, "bin/nginxtra"}" "$1" --basedir="#{Nginxtra::Config.base_dir}" --config="#{Nginxtra::Config.loaded_config_path}" --workingdir="#{workingdir}" --non-interactive
53
- }, :force => true
54
+ ), force: true
54
55
  @thor.chmod filename, 0755
55
56
  end
56
57
 
57
- run! %{#{sudo true}rm /etc/init.d/nginxtra} if File.exists? "/etc/init.d/nginxtra"
58
- run! %{#{sudo true}ln -s "#{File.join Nginxtra::Config.base_dir, filename}" /etc/init.d/nginxtra}
59
- run! %{#{sudo true}update-rc.d nginxtra defaults}
58
+ run! %(#{sudo true}rm /etc/init.d/nginxtra) if File.exist? "/etc/init.d/nginxtra"
59
+ run! %(#{sudo true}ln -s "#{File.join Nginxtra::Config.base_dir, filename}" /etc/init.d/nginxtra)
60
+ run! %(#{sudo true}update-rc.d nginxtra defaults)
60
61
  end
62
+ # rubocop:enable Metrics/AbcSize, Metrics/LineLength
61
63
 
62
64
  # Notify the user that installation should be up to date.
63
65
  def up_to_date
@@ -19,15 +19,11 @@ module Nginxtra
19
19
  end
20
20
 
21
21
  def ensure_in_rails_app
22
- unless in_rails_app?
23
- raise Nginxtra::Error::IllegalState.new "You must be in a rails root directory to run nginxtra_rails."
24
- end
22
+ raise Nginxtra::Error::IllegalState, "You must be in a rails root directory to run nginxtra_rails." unless in_rails_app?
25
23
  end
26
24
 
27
25
  def ensure_server_gem_installed
28
- unless passenger_installed?
29
- raise Nginxtra::Error::IllegalState.new "Please 'gem install passenger' to continue."
30
- end
26
+ raise Nginxtra::Error::IllegalState, "Please 'gem install passenger' to continue." unless passenger_installed?
31
27
  end
32
28
 
33
29
  def start_nginxtra
@@ -35,10 +31,10 @@ module Nginxtra
35
31
  environment = @thor.options["environment"]
36
32
  @thor.empty_directory "tmp" unless File.directory? "tmp"
37
33
  @thor.empty_directory "tmp/nginxtra" unless File.directory? "tmp/nginxtra"
38
- @thor.create_file config_path, %{nginxtra.simple_config do
39
- rails :port => #{port}, :environment => "#{environment}"
34
+ @thor.create_file config_path, %(nginxtra.simple_config do
35
+ rails port: #{port}, environment: "#{environment}"
40
36
  end
41
- }, :force => true
37
+ ), force: true
42
38
  @thor.invoke Nginxtra::CLI, ["start"], :basedir => basedir, :config => config_path, :workingdir => workingdir, :"non-interactive" => true
43
39
  @thor.say "Listening on http://localhost:#{port}/"
44
40
  @thor.say "Environment: #{environment}"
@@ -73,8 +69,8 @@ end
73
69
  end
74
70
 
75
71
  def in_rails_app?
76
- return true if File.exists? "script/rails"
77
- File.exists?("script/server") && File.exists?("app")
72
+ return true if File.exist? "script/rails"
73
+ File.exist?("script/server") && File.exist?("app")
78
74
  end
79
75
 
80
76
  def start_verbose_output
@@ -88,16 +84,17 @@ end
88
84
  @verbose_run = false
89
85
  end
90
86
 
87
+ # rubocop:disable Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
91
88
  def verbose_thread
92
89
  environment = @thor.options["environment"]
93
90
  log_path = "log/#{environment}.log"
94
91
 
95
- if File.exists? log_path
92
+ if File.exist? log_path
96
93
  log = File.open log_path, "r"
97
94
  log.seek 0, IO::SEEK_END
98
95
  else
99
96
  while @verbose_run
100
- if File.exists? log_path
97
+ if File.exist? log_path
101
98
  log = File.open log_path, "r"
102
99
  break
103
100
  end
@@ -112,7 +109,7 @@ end
112
109
 
113
110
  if line
114
111
  puts line
115
- puts line while(line = log.gets)
112
+ puts line while (line = log.gets)
116
113
  end
117
114
 
118
115
  sleep 0.1
@@ -120,6 +117,7 @@ end
120
117
  ensure
121
118
  log.close if log
122
119
  end
120
+ # rubocop:enable Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
123
121
  end
124
122
  end
125
123
  end
@@ -28,11 +28,11 @@ module Nginxtra
28
28
  # Save nginx config files to the proper config file path.
29
29
  def save_config_files
30
30
  files = @config.files
31
- raise Nginxtra::Error::InvalidConfig.new("Missing definition for nginx.conf", :header => "Missing definition for nginx.conf!", :message => "You must define your nginx.conf configuration in your nginxtra.conf.rb file.") unless files.include? "nginx.conf"
31
+ raise Nginxtra::Error::MissingNginxConfig unless files.include? "nginx.conf"
32
32
 
33
33
  @thor.inside Nginxtra::Config.config_dir do
34
34
  files.each do |filename|
35
- @thor.create_file filename, @config.file_contents(filename), :force => true
35
+ @thor.create_file filename, @config.file_contents(filename), force: true
36
36
  end
37
37
  end
38
38
  end
@@ -4,13 +4,13 @@ module Nginxtra
4
4
  class CLI < Thor
5
5
  include Thor::Actions
6
6
 
7
- class_option "force", :type => :boolean, :banner => "Force a task to happen, regardless of what nginxtra thinks", :aliases => "-f"
8
- class_option "trace", :type => :boolean, :banner => "Output stack traces on error"
9
- class_option "non-interactive", :type => :boolean, :banner => "If nginxtra would ask a question, it instead proceeds as if 'no' were the answer", :aliases => "-I"
10
- class_option "ignore-nginx-check", :type => :boolean, :banner => "Ignore the nginx check if installing"
11
- class_option "config", :type => :string, :banner => "Specify the configuration file to use", :aliases => "-c"
12
- class_option "basedir", :type => :string, :banner => "Specify the directory to store nginx files", :aliases => "-b"
13
- class_option "workingdir", :type => :string, :banner => "Specify the working directory", :aliases => "-w"
7
+ class_option "force", type: :boolean, banner: "Force a task to happen, regardless of what nginxtra thinks", aliases: "-f"
8
+ class_option "trace", type: :boolean, banner: "Output stack traces on error"
9
+ class_option "non-interactive", type: :boolean, banner: "If nginxtra would ask a question, it instead proceeds as if 'no' were the answer", aliases: "-I"
10
+ class_option "ignore-nginx-check", type: :boolean, banner: "Ignore the nginx check if installing"
11
+ class_option "config", type: :string, banner: "Specify the configuration file to use", aliases: "-c"
12
+ class_option "basedir", type: :string, banner: "Specify the directory to store nginx files", aliases: "-b"
13
+ class_option "workingdir", type: :string, banner: "Specify the working directory", aliases: "-w"
14
14
 
15
15
  map "-v" => "version"
16
16
 
@@ -25,11 +25,11 @@ module Nginxtra
25
25
  options to be ignored (and the defaults will be used in the resulting
26
26
  nginxtra.conf.rb). The result will be output to nginxtra.conf.rb in the current
27
27
  directory, unless an override value is specified with the --config option."
28
- method_option "nginx-bin", :type => :string, :banner => "Point to the compiled nginx to retrieve compile options", :aliases => "-n"
29
- method_option "nginx-conf", :type => :string, :banner => "Point to the nginx.conf file to retrieve the existing configuration", :aliases => "-F", :default => "nginx.conf"
30
- method_option "ignore-nginx-bin", :type => :boolean, :banner => "Ignore the nginx binary, and assume default compile time options", :aliases => "-N"
31
- method_option "output", :type => :boolean, :banner => "Output to standard out instead of to a file", :aliases => "-o"
32
- method_option "input", :type => :boolean, :banner => "Read nginx.conf from standard in instead of a file", :aliases => "-i"
28
+ method_option "nginx-bin", type: :string, banner: "Point to the compiled nginx to retrieve compile options", aliases: "-n"
29
+ method_option "nginx-conf", type: :string, banner: "Point to the nginx.conf file to retrieve the existing configuration", aliases: "-F", default: "nginx.conf"
30
+ method_option "ignore-nginx-bin", type: :boolean, banner: "Ignore the nginx binary, and assume default compile time options", aliases: "-N"
31
+ method_option "output", type: :boolean, banner: "Output to standard out instead of to a file", aliases: "-o"
32
+ method_option "input", type: :boolean, banner: "Read nginx.conf from standard in instead of a file", aliases: "-i"
33
33
  def convert
34
34
  Nginxtra::Error.protect self do
35
35
  Nginxtra::Actions::Convert.new(self, nil).convert
@@ -42,9 +42,9 @@ module Nginxtra
42
42
  --file is provided, something other than nginx.conf can be output. The --list
43
43
  option can be provided to list known config files. The --compile-options option
44
44
  can be provided to list compile time options being passed to nginx."
45
- method_option "compile-options", :type => :boolean, :banner => "Show compile options being used", :aliases => "-C"
46
- method_option "file", :type => :string, :banner => "The config file that is printed", :aliases => "-F", :default => "nginx.conf"
47
- method_option "list", :type => :boolean, :banner => "List known files", :aliases => "-l"
45
+ method_option "compile-options", type: :boolean, banner: "Show compile options being used", aliases: "-C"
46
+ method_option "file", type: :string, banner: "The config file that is printed", aliases: "-F", default: "nginx.conf"
47
+ method_option "list", type: :boolean, banner: "List known files", aliases: "-l"
48
48
  def print
49
49
  Nginxtra::Error.protect self do
50
50
  set_working_dir!
@@ -141,6 +141,7 @@ module Nginxtra
141
141
  end
142
142
 
143
143
  private
144
+
144
145
  def prepare_config!
145
146
  Nginxtra::Config.base_dir = options["basedir"]
146
147
  result = Nginxtra::Config.require! options["config"]
@@ -149,9 +150,7 @@ module Nginxtra
149
150
  end
150
151
 
151
152
  def set_working_dir!
152
- if options["workingdir"]
153
- Dir.chdir options["workingdir"]
154
- end
153
+ Dir.chdir options["workingdir"] if options["workingdir"]
155
154
  end
156
155
 
157
156
  class << self
@@ -6,19 +6,16 @@ module Nginxtra
6
6
  FILENAME = "nginxtra.conf.rb".freeze
7
7
  NGINX_CONF_FILENAME = "nginx.conf".freeze
8
8
  NGINX_PIDFILE_FILENAME = ".nginx_pid".freeze
9
- @@last_config = nil
10
9
 
11
- def initialize(*args)
10
+ def initialize(*_args)
12
11
  @requires_root = false
13
12
  @compile_options = []
14
13
  @partial_paths = []
15
14
  @file_paths = []
16
15
  @files = {}
17
- @@last_config = self
16
+ Nginxtra::Config.last_config = self
18
17
 
19
- if block_given?
20
- yield self
21
- end
18
+ yield self if block_given?
22
19
  end
23
20
 
24
21
  # Define an additional directory where partials can be found. The
@@ -50,7 +47,7 @@ module Nginxtra
50
47
  # gem partials.
51
48
  def partial_paths
52
49
  [].tap do |result|
53
- result.push *@partial_paths
50
+ result.push(*@partial_paths)
54
51
  result.push File.join(Nginxtra::Config.template_dir, "partials")
55
52
  result.push File.join(Nginxtra::Config.gem_template_dir, "partials")
56
53
  end
@@ -63,7 +60,7 @@ module Nginxtra
63
60
  # file templates.
64
61
  def file_paths
65
62
  [].tap do |result|
66
- result.push *@file_paths
63
+ result.push(*@file_paths)
67
64
  result.push File.join(Nginxtra::Config.template_dir, "files")
68
65
  result.push File.join(Nginxtra::Config.gem_template_dir, "files")
69
66
  end
@@ -75,7 +72,7 @@ module Nginxtra
75
72
  # ...
76
73
  # end
77
74
  def config(&block)
78
- instance_eval &block
75
+ instance_eval(&block)
79
76
  self
80
77
  end
81
78
 
@@ -106,9 +103,9 @@ module Nginxtra
106
103
  # add a Wno-error compilation option, and add the passenger module
107
104
  # to the proper passenger path.
108
105
  def require_passenger!
109
- compile_option %{--with-http_gzip_static_module}
110
- compile_option %{--with-cc-opt=-Wno-error}
111
- compile_option %{--add-module="#{Nginxtra::Config.passenger_config_dir}"}
106
+ compile_option %(--with-http_gzip_static_module)
107
+ compile_option %(--with-cc-opt=-Wno-error)
108
+ compile_option %(--add-module="#{Nginxtra::Config.passenger_config_dir}")
112
109
  end
113
110
 
114
111
  # Obtain the compile options that have been configured.
@@ -130,10 +127,10 @@ module Nginxtra
130
127
  # end
131
128
  def compile_option(opt)
132
129
  opt = "--#{opt}" unless opt =~ /^--/
133
- raise Nginxtra::Error::InvalidConfig.new("Invalid compilation option --prefix", :header => "Invalid compilation option --prefix", :message => "The --prefix compile option is not allowed with nginxtra. It is reserved so nginxtra can control where nginx is compiled and run from.") if opt =~ /--prefix=/
134
- raise Nginxtra::Error::InvalidConfig.new("Invalid compilation option --sbin-path", :header => "Invalid compilation option --sbin-path", :message => "The --sbin-path compile option is not allowed with nginxtra. It is reserved so nginxtra can control what binary is used to run nginx.") if opt =~ /--sbin-path=/
135
- raise Nginxtra::Error::InvalidConfig.new("Invalid compilation option --conf-path", :header => "Invalid compilation option --conf-path", :message => "The --conf-path compile option is not allowed with nginxtra. It is reserved so nginxtra can control the configuration entirely via #{Nginxtra::Config::FILENAME}.") if opt =~ /--conf-path=/
136
- raise Nginxtra::Error::InvalidConfig.new("Invalid compilation option --pid-path", :header => "Invalid compilation option --pid-path", :message => "The --pid-path compile option is not allowed with nginxtra. It is reserved so nginxtra can control where the pid file is created.") if opt =~ /--pid-path=/
130
+ raise Nginxtra::Error::InvalidCompilationOption, "prefix" if opt =~ /--prefix=/
131
+ raise Nginxtra::Error::InvalidCompilationOption, "sbin-path" if opt =~ /--sbin-path=/
132
+ raise Nginxtra::Error::InvalidCompilationOption, "conf-path" if opt =~ /--conf-path=/
133
+ raise Nginxtra::Error::InvalidCompilationOption, "pid-path" if opt =~ /--pid-path=/
137
134
  @compile_options << opt
138
135
  end
139
136
 
@@ -155,10 +152,7 @@ module Nginxtra
155
152
  end
156
153
 
157
154
  class << self
158
- # Obtain the last Nginxtra::Config object that was created.
159
- def last_config
160
- @@last_config
161
- end
155
+ attr_accessor :last_config
162
156
 
163
157
  # Obtain the config file path based on the current directory.
164
158
  # This will be the path to the first nginxtra.conf.rb found
@@ -169,41 +163,40 @@ module Nginxtra
169
163
  def path
170
164
  path = File.absolute_path "."
171
165
  config = File.join path, FILENAME
172
- return config if File.exists? config
166
+ return config if File.exist? config
173
167
  config = File.join path, "config", FILENAME
174
- return config if File.exists? config
168
+ return config if File.exist? config
175
169
  path = File.dirname path
176
170
 
177
- begin
171
+ loop do
178
172
  config = File.join path, FILENAME
179
- return config if File.exists? config
173
+ return config if File.exist? config
180
174
  path = File.dirname path
181
- end until path == "/"
175
+ break if path == "/"
176
+ end
182
177
 
183
178
  config = File.join path, FILENAME
184
- config if File.exists? config
179
+ config if File.exist? config
185
180
  end
186
181
 
187
182
  # Retrieve the path to the config file that was loaded.
188
- def loaded_config_path
189
- @loaded_config_path
190
- end
183
+ attr_reader :loaded_config_path
191
184
 
192
185
  # Determine where the config file is and require it. Return the
193
186
  # resulting config loaded by the path.
194
187
  # Nginxtra::Error::MissingConfig will be raised if the config
195
188
  # file cannot be found.
196
189
  def require!(config_path = nil)
197
- if config_path
198
- config_path = File.absolute_path config_path
199
- else
200
- config_path = path
201
- end
202
-
203
- raise Nginxtra::Error::MissingConfig.new("Cannot find #{FILENAME} to configure nginxtra!") unless config_path
204
- raise Nginxtra::Error::MissingConfig.new("Missing file #{config_path} to configure nginxtra!") unless File.exists?(config_path)
190
+ config_path = if config_path
191
+ File.absolute_path config_path
192
+ else
193
+ path
194
+ end
195
+
196
+ raise Nginxtra::Error::MissingConfig, "Cannot find #{FILENAME} to configure nginxtra!" unless config_path
197
+ raise Nginxtra::Error::MissingConfig, "Missing file #{config_path} to configure nginxtra!" unless File.exist?(config_path)
205
198
  require config_path
206
- raise Nginxtra::Error::InvalidConfig.new("No configuration is specified in #{config_path}!") unless last_config
199
+ raise Nginxtra::Error::NoConfigSpecified, config_path unless last_config
207
200
  @loaded_config_path = config_path
208
201
  last_config
209
202
  end
@@ -298,7 +291,7 @@ module Nginxtra
298
291
  # be found.
299
292
  def passenger_spec
300
293
  @passenger_spec ||= Gem::Specification.find_by_name("passenger").tap do |spec|
301
- raise InvalidConfig.new("Missing passenger gem", :header => "Missing passenger gem!", :message => "You cannot reference passenger unless the passenger gem is installed!") if spec.nil?
294
+ raise Nginxtra::Error::MissingPassengerGem if spec.nil?
302
295
  end
303
296
  end
304
297
 
@@ -308,7 +301,7 @@ module Nginxtra
308
301
 
309
302
  # Determine if nginx is running, based on the pidfile.
310
303
  def nginx_running?
311
- return false unless File.exists? nginx_pidfile
304
+ return false unless File.exist? nginx_pidfile
312
305
  pid = File.read(nginx_pidfile).strip
313
306
  Process.getpgid pid.to_i
314
307
  true
@@ -372,9 +365,9 @@ module Nginxtra
372
365
  def initialize(filename, config, &block)
373
366
  @filename = filename
374
367
  @config = config
375
- @indentation = Nginxtra::Config::Indentation.new :indent_size => 4
368
+ @indentation = Nginxtra::Config::Indentation.new indent_size: 4
376
369
  @file_contents = []
377
- instance_eval &block
370
+ instance_eval(&block)
378
371
  end
379
372
 
380
373
  # The file contents that were defined for this config file.
@@ -435,9 +428,9 @@ module Nginxtra
435
428
  empty_config_line unless @file_contents.empty? || @begin_of_block
436
429
  bare_config_line "#{name} {"
437
430
  @begin_of_block = true
438
- @indentation + 1
431
+ @indentation.increment
439
432
  yield if block_given?
440
- @indentation - 1
433
+ @indentation.decrement
441
434
  bare_config_line "}"
442
435
  @end_of_block = true
443
436
  end
@@ -478,14 +471,14 @@ module Nginxtra
478
471
  # in will be invoked (if given) if the template invokes yield.
479
472
  def process_template!(template, options = {}, yielder = nil)
480
473
  if template.respond_to? :call
481
- block = Proc.new { instance_eval &yielder if yielder }
474
+ block = proc { instance_eval(&yielder) if yielder }
482
475
  instance_exec options, block, &template
483
476
  else
484
477
  process_template_with_yields! template do |x|
485
478
  if x
486
479
  options[x.to_sym]
487
- else
488
- instance_eval &yielder if yielder
480
+ elsif yielder
481
+ instance_eval(&yielder)
489
482
  end
490
483
  end
491
484
  end
@@ -522,45 +515,50 @@ module Nginxtra
522
515
  # Output the passenger_root line, including the proper passenger
523
516
  # gem path.
524
517
  def passenger_root!
525
- config_line %{passenger_root #{Nginxtra::Config.passenger_spec.gem_dir}}
518
+ config_line %(passenger_root #{Nginxtra::Config.passenger_spec.gem_dir})
526
519
  end
527
520
 
528
521
  # Output the passenger_ruby, including the proper ruby path.
529
522
  def passenger_ruby!
530
- config_line %{passenger_ruby #{Nginxtra::Config.ruby_path}}
523
+ config_line %(passenger_ruby #{Nginxtra::Config.ruby_path})
531
524
  end
532
525
 
533
526
  # Output that passenger is enabled in this block.
534
527
  def passenger_on!
535
- config_line %{passenger_enabled on}
528
+ config_line %(passenger_enabled on)
536
529
  end
537
530
 
538
531
  private
532
+
533
+ def full_partial_paths(partial_name)
534
+ @config.partial_paths.lazy.map do |path|
535
+ File.join path, @filename, "#{partial_name}.rb"
536
+ end
537
+ end
538
+
539
539
  def partial?(partial_name)
540
540
  return true if Nginxtra::Config::Extension.partial? @filename, partial_name
541
541
 
542
- @config.partial_paths.any? do |path|
543
- File.exists? File.join(path, "#{@filename}/#{partial_name}.rb")
542
+ full_partial_paths(partial_name).any? do |path|
543
+ File.exist? path
544
544
  end
545
545
  end
546
546
 
547
547
  def invoke_partial(partial_name, args, block)
548
- if Nginxtra::Config::Extension.partial? @filename, partial_name
549
- partial_path = Nginxtra::Config::Extension.partial @filename, partial_name
550
- else
551
- partial_path = @config.partial_paths.map do |path|
552
- File.join path, "#{@filename}/#{partial_name}.rb"
553
- end.find do |path|
554
- File.exists? path
555
- end
556
- end
548
+ partial_path = if Nginxtra::Config::Extension.partial? @filename, partial_name
549
+ Nginxtra::Config::Extension.partial @filename, partial_name
550
+ else
551
+ full_partial_paths(partial_name).find do |path|
552
+ File.exist? path
553
+ end
554
+ end
557
555
 
558
556
  if args.empty?
559
557
  partial_options = {}
560
- elsif args.length == 1 && args.first.kind_of?(Hash)
558
+ elsif args.length == 1 && args.first.is_a?(Hash)
561
559
  partial_options = args.first
562
560
  else
563
- raise InvalidConfig.new("Invalid partial arguments", :header => "Invalid partial arguments!", :message => "You can only pass 0 arguments or 1 hash to a partial!")
561
+ raise Nginxtra::Error::InvalidPartialArguments
564
562
  end
565
563
 
566
564
  process_template! partial_path, partial_options, block
@@ -592,9 +590,9 @@ module Nginxtra
592
590
  end
593
591
 
594
592
  config_files = file_options.map(&:keys).inject([], &:+).uniq.map do |x|
595
- file_options.select do |option|
593
+ file_options.find do |option|
596
594
  option.include? x
597
- end.first[x]
595
+ end[x]
598
596
  end
599
597
 
600
598
  process_files! config_files
@@ -608,13 +606,10 @@ module Nginxtra
608
606
  def find_config_files!(path)
609
607
  files_hash = {}
610
608
 
611
- Dir["#{path}/**/*.rb"].select do |x|
612
- File.file? x
613
- end.map do |x|
614
- file_name = x.sub /^#{Regexp.quote "#{path}"}\/(.*)\.rb$/, "\\1"
615
- { :path => x, :config_file => file_name }
616
- end.each do |x|
617
- files_hash[x[:config_file]] = x
609
+ Dir["#{path}/**/*.rb"].each do |x|
610
+ next unless File.file? x
611
+ file_name = x.sub %r{^#{Regexp.quote path.to_s}/(.*)\.rb$}, "\\1"
612
+ files_hash[file_name] = { path: x, config_file: file_name }
618
613
  end
619
614
 
620
615
  files_hash
@@ -653,19 +648,25 @@ module Nginxtra
653
648
  @value == 0
654
649
  end
655
650
 
656
- def -(amount)
657
- self + (-amount)
651
+ def decrement
652
+ adjust(-1)
658
653
  end
659
654
 
660
- def +(amount)
661
- @value += amount
662
- raise Nginxtra::Error::ConvertFailed.new("Missing block end!") if @value < 0
663
- @value
655
+ def increment
656
+ adjust(1)
664
657
  end
665
658
 
666
659
  def to_s
667
660
  " " * indent_size * @value
668
661
  end
662
+
663
+ private
664
+
665
+ def adjust(amount)
666
+ @value += amount
667
+ raise Nginxtra::Error::ConvertFailed, "Missing block end!" if @value < 0
668
+ @value
669
+ end
669
670
  end
670
671
  end
671
672
  end
@@ -677,5 +678,5 @@ end
677
678
  # ...
678
679
  # end
679
680
  def nginxtra(*args, &block)
680
- Nginxtra::Config.new *args, &block
681
+ Nginxtra::Config.new(*args, &block)
681
682
  end