Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add the force option to compile.

  • Loading branch information...
commit 9effbabe4ac0c960bcbdeabd35ae4341c7df3bf3 1 parent 35f82f4
@mikestone authored
View
8 lib/nginxtra/actions/compile.rb
@@ -1,11 +1,14 @@
module Nginxtra
module Actions
# The Nginxtra::Actions::Compile class encapsulates compiling
- # nginx so it is ready with the specified compile options.
+ # nginx so it is ready with the specified compile options. An
+ # optional option of :force can be passed with true to make
+ # compilation happen no matter what.
class Compile
- def initialize(thor, config)
+ def initialize(thor, config, options = {})
@thor = thor
@config = config
+ @options = options
end
# Run the full compilation of nginx.
@@ -35,6 +38,7 @@ def make(*args)
# if the last compile options equal the current options, or if
# the force option was passed in at construction time.
def should_compile?
+ return true if @options[:force]
Nginxtra::Status[:last_compile_options] != @config.compile_options
end
View
3  lib/nginxtra/cli.rb
@@ -4,9 +4,10 @@ module Nginxtra
class CLI < Thor
include Thor::Actions
desc "compile", "Compiles nginx based on nginxtra.conf.rb"
+ method_option "force", :type => :boolean, :banner => "Force compilation to happen", :aliases => "-f"
def compile
- Nginxtra::Actions::Compile.new(self, Nginxtra::Config.require!).compile
+ Nginxtra::Actions::Compile.new(self, Nginxtra::Config.require!, :force => options["force"]).compile
end
end
end
View
13 spec/compile_spec.rb
@@ -41,4 +41,17 @@
Nginxtra::Status.should_not_receive(:[]=)
Nginxtra::Actions::Compile.new(thor_mock, config_mock).compile
end
+
+ it "recompiles if force is passed in" do
+ thor_mock.stub(:inside).with(src_dir).and_yield
+ thor_mock.should_receive(:run).with("./configure --prefix=#{build_dir} --option1 --option2")
+ thor_mock.should_receive(:run).with("make")
+ thor_mock.should_receive(:run).with("make install")
+ config_mock.stub(:compile_options).and_return("--option1 --option2")
+ Nginxtra::Status.stub(:[]).with(:last_compile_options).and_return("--option1 --option2")
+ Time.stub(:now).and_return(:fake_time)
+ Nginxtra::Status.should_receive(:[]=).with(:last_compile_options, "--option1 --option2")
+ Nginxtra::Status.should_receive(:[]=).with(:last_compile_time, :fake_time)
+ Nginxtra::Actions::Compile.new(thor_mock, config_mock, :force => true).compile
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.