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
# File 'lib/spring/env.rb', line 13

def initialize(root = nil)
  @root = root || Pathname.new(File.expand_path('.'))
end

Instance Attribute Details

#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



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

def app_name
  root.basename
end

#pidObject



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

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



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

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

#server_running?Boolean

Returns:

  • (Boolean)


50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/spring/env.rb', line 50

def server_running?
  if pidfile_path.exist?
    pidfile = pidfile_path.open('r')
    !pidfile.flock(File::LOCK_EX | File::LOCK_NB)
  else
    false
  end
ensure
  if pidfile
    pidfile.flock(File::LOCK_UN)
    pidfile.close
  end
end

#socket_nameObject



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

def socket_name
  socket_path.to_s
end

#socket_pathObject



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

def socket_path
  tmp_path.join("spring")
end

#tmp_pathObject



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

def tmp_path
  path = default_tmp_path
  FileUtils.mkdir_p(path) unless path.exist?
  path
end

#versionObject



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

def version
  Spring::VERSION
end