Class: Nginxtra::Actions::Compile

Inherits:
Object
  • Object
show all
Includes:
Nginxtra::Action
Defined in:
lib/nginxtra/actions/compile.rb

Overview

The Nginxtra::Actions::Compile class encapsulates compiling 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.

Instance Method Summary collapse

Methods included from Nginxtra::Action

#daemon, #initialize

Instance Method Details

#compileObject

Run the full compilation of nginx.



11
12
13
14
15
16
17
18
# File 'lib/nginxtra/actions/compile.rb', line 11

def compile
  return up_to_date unless should_compile?
  copy_to_base
  configure
  make
  make "install"
  update_last_compile
end

#configureObject

Configure nginx with the specified compile options.



26
27
28
29
30
# File 'lib/nginxtra/actions/compile.rb', line 26

def configure
  @thor.inside Nginxtra::Config.src_dir do
    run! "sh configure --prefix=#{Nginxtra::Config.build_dir} --conf-path=#{Nginxtra::Config.nginx_config} --pid-path=#{Nginxtra::Config.nginx_pidfile} #{@config.compile_options}"
  end
end

#copy_to_baseObject

Copy the nginx source directory to the base directory.



21
22
23
# File 'lib/nginxtra/actions/compile.rb', line 21

def copy_to_base
  @thor.directory "vendor/nginx", Nginxtra::Config.src_dir
end

#different_compile_options?Boolean

Determine if the compile options differ from those last compiled with.

Returns:

  • (Boolean)


50
51
52
# File 'lib/nginxtra/actions/compile.rb', line 50

def different_compile_options?
  Nginxtra::Status[:last_compile_options] != @config.compile_options
end

#different_nginx_version?Boolean

Determine if the last nginx compiled version is different from the current nginx version.

Returns:

  • (Boolean)


56
57
58
# File 'lib/nginxtra/actions/compile.rb', line 56

def different_nginx_version?
  Nginxtra::Status[:last_compile_version] != Nginxtra::Config.nginx_version
end

#make(*args) ⇒ Object

Run make against the configured nginx.



33
34
35
36
37
# File 'lib/nginxtra/actions/compile.rb', line 33

def make(*args)
  @thor.inside Nginxtra::Config.src_dir do
    run! ["make", *args].join(" ")
  end
end

#should_compile?Boolean

Determine if compiling should happen. This will return false if the last compile options equal the current options and the last compile version is the same as the current nginx version, or if the force option was passed in at construction time.

Returns:

  • (Boolean)


43
44
45
46
# File 'lib/nginxtra/actions/compile.rb', line 43

def should_compile?
  return true if force?
  different_compile_options? || different_nginx_version?
end

#up_to_dateObject

Notify the user that the compilation is up to date



69
70
71
# File 'lib/nginxtra/actions/compile.rb', line 69

def up_to_date
  @thor.say "nginx compilation is up to date"
end

#update_last_compileObject

Update Nginxtra::Status with the last compile time and options.



62
63
64
65
66
# File 'lib/nginxtra/actions/compile.rb', line 62

def update_last_compile
  Nginxtra::Status[:last_compile_options] = @config.compile_options
  Nginxtra::Status[:last_compile_time] = Time.now
  Nginxtra::Status[:last_compile_version] = Nginxtra::Config.nginx_version
end