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.
-
#root ⇒ Object
readonly
Returns the value of attribute root.
Instance Method Summary collapse
- #app_name ⇒ Object
- #bundle_mtime ⇒ Object
-
#initialize(root = nil) ⇒ Env
constructor
A new instance of Env.
- #log(message) ⇒ Object
- #pid ⇒ Object
- #pidfile_path ⇒ 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.
11 12 13 |
# File 'lib/spring/env.rb', line 11 def log_file @log_file end |
#root ⇒ Object (readonly)
Returns the value of attribute root.
11 12 13 |
# File 'lib/spring/env.rb', line 11 def root @root end |
Instance Method Details
#app_name ⇒ Object
47 48 49 |
# File 'lib/spring/env.rb', line 47 def app_name root.basename end |
#bundle_mtime ⇒ Object
63 64 65 |
# File 'lib/spring/env.rb', line 63 def bundle_mtime [Bundler.default_lockfile, Bundler.default_gemfile].select(&:exist?).map(&:mtime).max end |
#log(message) ⇒ Object
67 68 69 70 |
# File 'lib/spring/env.rb', line 67 def log() log_file.puts "[#{Time.now}] #{}" log_file.flush end |
#pid ⇒ Object
40 41 42 43 44 45 |
# File 'lib/spring/env.rb', line 40 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
36 37 38 |
# File 'lib/spring/env.rb', line 36 def pidfile_path tmp_path.join("spring.pid") end |
#server_running? ⇒ Boolean
51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/spring/env.rb', line 51 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
32 33 34 |
# File 'lib/spring/env.rb', line 32 def socket_name socket_path.to_s end |
#socket_path ⇒ Object
28 29 30 |
# File 'lib/spring/env.rb', line 28 def socket_path tmp_path.join("spring") end |
#tmp_path ⇒ Object
22 23 24 25 26 |
# File 'lib/spring/env.rb', line 22 def tmp_path path = default_tmp_path FileUtils.mkdir_p(path) unless path.exist? path end |