Class: Spring::Env

Inherits:
Object
  • Object
show all
Defined in:
lib/spring/env.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root = nil) ⇒ Env

Returns a new instance of Env.



13
14
15
16
# File 'lib/spring/env.rb', line 13

def initialize(root = nil)
  @root     = root || Pathname.new(File.expand_path('.'))
  @log_file = File.open(ENV["SPRING_LOG"] || "/dev/null", "a")
end

Instance Attribute Details

#log_fileObject (readonly)

Returns the value of attribute log_file.



11
12
13
# File 'lib/spring/env.rb', line 11

def log_file
  @log_file
end

#rootObject (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_nameObject



47
48
49
# File 'lib/spring/env.rb', line 47

def app_name
  root.basename
end

#bundle_mtimeObject



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(message)
  log_file.puts "[#{Time.now}] #{message}"
  log_file.flush
end

#pidObject



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_pathObject



36
37
38
# File 'lib/spring/env.rb', line 36

def pidfile_path
  tmp_path.join("spring.pid")
end

#server_running?Boolean

Returns:

  • (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_nameObject



32
33
34
# File 'lib/spring/env.rb', line 32

def socket_name
  socket_path.to_s
end

#socket_pathObject



28
29
30
# File 'lib/spring/env.rb', line 28

def socket_path
  tmp_path.join("spring")
end

#tmp_pathObject



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

#versionObject



18
19
20
# File 'lib/spring/env.rb', line 18

def version
  Spring::VERSION
end