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.



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

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

Instance Attribute Details

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



58
59
60
# File 'lib/spring/env.rb', line 58

def app_name
  root.basename
end

#application_idObject



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

def application_id
  Digest::MD5.hexdigest(root.to_s)
end

#bundle_mtimeObject



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

#pidObject



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_pathObject



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

def pidfile_path
  tmp_path.join("#{application_id}.pid")
end

#rootObject



21
22
23
# File 'lib/spring/env.rb', line 21

def root
  @root ||= Spring.application_root_path
end

#server_running?Boolean

Returns:

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



43
44
45
# File 'lib/spring/env.rb', line 43

def socket_name
  socket_path.to_s
end

#socket_pathObject



39
40
41
# File 'lib/spring/env.rb', line 39

def socket_path
  tmp_path.join(application_id)
end

#tmp_pathObject



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

#versionObject



25
26
27
# File 'lib/spring/env.rb', line 25

def version
  Spring::VERSION
end