Class: Expedite::Env
- Inherits:
-
Object
- Object
- Expedite::Env
- Defined in:
- lib/expedite/env.rb
Instance Attribute Summary collapse
-
#app_name ⇒ Object
Returns the value of attribute app_name.
-
#application_id ⇒ Object
Returns the value of attribute application_id.
-
#applications ⇒ Object
readonly
Returns the value of attribute applications.
-
#bundler ⇒ Object
Returns the value of attribute bundler.
-
#log_file ⇒ Object
Returns the value of attribute log_file.
-
#root ⇒ Object
Returns the value of attribute root.
Instance Method Summary collapse
- #graceful_termination_timeout ⇒ Object
- #helper_path ⇒ Object
-
#initialize(root: nil, app_name: nil, log_file: nil, bundler: true) ⇒ Env
constructor
The environment containing the target application.
- #load_helper ⇒ Object
- #log(message) ⇒ Object
- #pidfile_path ⇒ Object
- #server_command ⇒ Object
- #socket_path ⇒ Object
- #tmp_path ⇒ Object
- #version ⇒ Object
Constructor Details
#initialize(root: nil, app_name: nil, log_file: nil, bundler: true) ⇒ Env
The environment containing the target application.
The root and app_name are used to derive the socket.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/expedite/env.rb', line 21 def initialize(root: nil, app_name: nil, log_file: nil, bundler: true) # Use realpath so that directories that are symlinked end up with # the same root. This is important for getting the correct socket. @root = File.realpath(root || Dir.pwd) @app_name = app_name || File.basename(@root) @log_file = log_file || File.open(File::NULL, "a") @bundler = bundler @application_id = Digest::SHA1.hexdigest(@root + "|" + @app_name) @tmp_path = nil # TODO: @applications should only be available in the server @applications = Server::ApplicationManager.new(self) end |
Instance Attribute Details
#app_name ⇒ Object
Returns the value of attribute app_name.
9 10 11 |
# File 'lib/expedite/env.rb', line 9 def app_name @app_name end |
#application_id ⇒ Object
Returns the value of attribute application_id.
9 10 11 |
# File 'lib/expedite/env.rb', line 9 def application_id @application_id end |
#applications ⇒ Object (readonly)
Returns the value of attribute applications.
10 11 12 |
# File 'lib/expedite/env.rb', line 10 def applications @applications end |
#bundler ⇒ Object
Returns the value of attribute bundler.
9 10 11 |
# File 'lib/expedite/env.rb', line 9 def bundler @bundler end |
#log_file ⇒ Object
Returns the value of attribute log_file.
9 10 11 |
# File 'lib/expedite/env.rb', line 9 def log_file @log_file end |
#root ⇒ Object
Returns the value of attribute root.
8 9 10 |
# File 'lib/expedite/env.rb', line 8 def root @root end |
Instance Method Details
#graceful_termination_timeout ⇒ Object
73 74 75 |
# File 'lib/expedite/env.rb', line 73 def graceful_termination_timeout 2 end |
#helper_path ⇒ Object
77 78 79 |
# File 'lib/expedite/env.rb', line 77 def helper_path Pathname.new(root).join("expedite_helper.rb") end |
#load_helper ⇒ Object
81 82 83 84 85 86 87 |
# File 'lib/expedite/env.rb', line 81 def load_helper path = helper_path if path.exist? log "loading #{path}" load(path) end end |
#log(message) ⇒ Object
58 59 60 61 |
# File 'lib/expedite/env.rb', line 58 def log() log_file.puts "[#{Time.now}] [#{Process.pid}] #{}" log_file.flush end |
#pidfile_path ⇒ Object
54 55 56 |
# File 'lib/expedite/env.rb', line 54 def pidfile_path tmp_path.join("#{application_id}.pid") end |
#server_command ⇒ Object
63 64 65 66 67 68 69 70 71 |
# File 'lib/expedite/env.rb', line 63 def server_command bin_expedite = File.("../../../bin/expedite", __FILE__) cmd = if bundler "bundle exec #{bin_expedite}" else bin_expedite end "#{cmd} server --background" end |
#socket_path ⇒ Object
50 51 52 |
# File 'lib/expedite/env.rb', line 50 def socket_path tmp_path.join(application_id) end |
#tmp_path ⇒ Object
40 41 42 43 44 45 46 47 48 |
# File 'lib/expedite/env.rb', line 40 def tmp_path return @tmp_path unless @tmp_path.nil? require "tmpdir" path = Pathname.new(File.join(Dir.tmpdir, "expedite-#{Process.uid}")) require "fileutils" FileUtils.mkdir_p(path) unless path.exist? @tmp_path = path end |