Class: Guard::Redis

Inherits:
Guard
  • Object
show all
Defined in:
lib/guard/redis.rb

Instance Method Summary collapse

Instance Method Details

#configObject



48
49
50
51
52
53
54
# File 'lib/guard/redis.rb', line 48

def config
  "daemonize yes\npidfile \#{pidfile_path}\nport \#{port}\n"
end

#executableObject



60
61
62
# File 'lib/guard/redis.rb', line 60

def executable
  options.fetch(:executable) { 'redis-server' }
end

#last_operation_succeeded?Boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/guard/redis.rb', line 68

def last_operation_succeeded?
  $?.success?
end

#pidObject



56
57
58
# File 'lib/guard/redis.rb', line 56

def pid
  (File.exist?(pidfile_path) && File.read(pidfile_path).to_i) || @pid
end

#pidfile_pathObject



42
43
44
45
46
# File 'lib/guard/redis.rb', line 42

def pidfile_path
  options.fetch(:pidfile) {
    File.expand_path('/tmp/redis.pid', File.dirname(__FILE__))
  }
end

#portObject



64
65
66
# File 'lib/guard/redis.rb', line 64

def port
  options.fetch(:port) { 6379 }
end

#reloadObject



27
28
29
30
31
32
# File 'lib/guard/redis.rb', line 27

def reload
  UI.info "Reloading Redis..."
  stop
  start
  UI.info "Redis successfully restarted."
end

#reload_on_change?Boolean

Returns:

  • (Boolean)


72
73
74
# File 'lib/guard/redis.rb', line 72

def reload_on_change?
  options.fetch(:reload_on_change) { false }
end

#run_allObject



34
35
36
# File 'lib/guard/redis.rb', line 34

def run_all
  true
end

#run_on_change(paths) ⇒ Object



38
39
40
# File 'lib/guard/redis.rb', line 38

def run_on_change(paths)
  reload if reload_on_change?
end

#startObject



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/guard/redis.rb', line 6

def start
  UI.info "Starting Redis on port #{port}..."
  @pid = nil
  IO.popen("#{executable} -", 'w+') do |server|
    @pid = server.pid
    server.write(config)
    server.close_write
  end
  UI.info "Redis is running with PID #{pid}"
  last_operation_succeeded?
end

#stopObject



18
19
20
21
22
23
24
25
# File 'lib/guard/redis.rb', line 18

def stop
  if pid
    UI.info "Sending TERM signal to Redis (#{pid})"
    Process.kill("TERM", pid)
    @pid = nil
    true
  end
end