Class: Spring::Env
- Inherits:
-
Object
- Object
- Spring::Env
- Defined in:
- lib/spring/env.rb
Instance Attribute Summary collapse
-
#log_file ⇒ Object
readonly
Returns the value of attribute log_file.
Instance Method Summary collapse
- #app_name ⇒ Object
- #application_id ⇒ Object
- #bundle_mtime ⇒ Object
-
#initialize(root = nil) ⇒ Env
constructor
A new instance of Env.
- #log(message) ⇒ Object
- #pid ⇒ Object
- #pidfile_path ⇒ Object
- #root ⇒ Object
- #server_running? ⇒ Boolean
- #socket_name ⇒ Object
- #socket_path ⇒ Object
- #tmp_path ⇒ Object
- #version ⇒ Object
Constructor Details
Instance Attribute Details
#log_file ⇒ Object (readonly)
Returns the value of attribute log_file.
14 15 16 |
# File 'lib/spring/env.rb', line 14 def log_file @log_file end |
Instance Method Details
#app_name ⇒ Object
58 59 60 |
# File 'lib/spring/env.rb', line 58 def app_name root.basename end |
#application_id ⇒ Object
35 36 37 |
# File 'lib/spring/env.rb', line 35 def application_id Digest::MD5.hexdigest(root.to_s) end |
#bundle_mtime ⇒ Object
74 75 76 |
# File 'lib/spring/env.rb', line 74 def bundle_mtime [Bundler.default_lockfile, Bundler.default_gemfile].select(&:exist?).map(&:mtime).max end |
#log(message) ⇒ Object
78 79 80 81 |
# File 'lib/spring/env.rb', line 78 def log() log_file.puts "[#{Time.now}] #{}" log_file.flush end |
#pid ⇒ Object
51 52 53 54 55 56 |
# File 'lib/spring/env.rb', line 51 def pid pidfile_path.exist? ? pidfile_path.read.to_i : nil rescue Errno::ENOENT # This can happen if the pidfile is removed after we check it # exists end |
#pidfile_path ⇒ Object
47 48 49 |
# File 'lib/spring/env.rb', line 47 def pidfile_path tmp_path.join("#{application_id}.pid") end |
#root ⇒ Object
21 22 23 |
# File 'lib/spring/env.rb', line 21 def root @root ||= Spring.application_root_path end |
#server_running? ⇒ Boolean
62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/spring/env.rb', line 62 def server_running? pidfile = pidfile_path.open('r') !pidfile.flock(File::LOCK_EX | File::LOCK_NB) rescue Errno::ENOENT false ensure if pidfile pidfile.flock(File::LOCK_UN) pidfile.close end end |
#socket_name ⇒ Object
43 44 45 |
# File 'lib/spring/env.rb', line 43 def socket_name socket_path.to_s end |
#socket_path ⇒ Object
39 40 41 |
# File 'lib/spring/env.rb', line 39 def socket_path tmp_path.join(application_id) end |
#tmp_path ⇒ Object
29 30 31 32 33 |
# File 'lib/spring/env.rb', line 29 def tmp_path path = Pathname.new(Dir.tmpdir + "/spring") FileUtils.mkdir_p(path) unless path.exist? path end |