Class: Guard::Redis
Instance Method Summary collapse
- #config ⇒ Object
- #executable ⇒ Object
- #last_operation_succeeded? ⇒ Boolean
- #pid ⇒ Object
- #pidfile_path ⇒ Object
- #port ⇒ Object
- #reload ⇒ Object
- #reload_on_change? ⇒ Boolean
- #run_all ⇒ Object
- #run_on_change(paths) ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
Instance Method Details
#config ⇒ Object
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 |
#executable ⇒ Object
60 61 62 |
# File 'lib/guard/redis.rb', line 60 def executable .fetch(:executable) { 'redis-server' } end |
#last_operation_succeeded? ⇒ Boolean
68 69 70 |
# File 'lib/guard/redis.rb', line 68 def last_operation_succeeded? $?.success? end |
#pid ⇒ Object
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_path ⇒ Object
42 43 44 45 46 |
# File 'lib/guard/redis.rb', line 42 def pidfile_path .fetch(:pidfile) { File.('/tmp/redis.pid', File.dirname(__FILE__)) } end |
#port ⇒ Object
64 65 66 |
# File 'lib/guard/redis.rb', line 64 def port .fetch(:port) { 6379 } end |
#reload ⇒ Object
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
72 73 74 |
# File 'lib/guard/redis.rb', line 72 def reload_on_change? .fetch(:reload_on_change) { false } end |
#run_all ⇒ Object
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 |
#start ⇒ Object
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 |
#stop ⇒ Object
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 |