Skip to content

Commit

Permalink
Move handle_change to watcher_handler
Browse files Browse the repository at this point in the history
  • Loading branch information
faustinoaq committed Mar 31, 2017
1 parent ba9cc4b commit 2ddcd3f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
11 changes: 1 addition & 10 deletions src/kemal-watcher.cr
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@ require "secure_random"

require "./kemal-watcher/*"


module Kemal
SOCKETS = [] of HTTP::WebSocket
WEBSOCKETPATH = SecureRandom.hex 4

# Uses Watcher.watch shard to guard files
def self.watcher(files)
puts " Your KemalBot is vigilant. beep-boop..."
spawn do
puts " Your KemalBot is vigilant. beep-boop..."
watch files do |event|
event.on_change do |files|
files.each do |file, time|
Expand All @@ -24,14 +23,6 @@ module Kemal
end
end

# Handle change when event.on_change and
# send reload message to all clients
def self.handle_change
SOCKETS.each do |socket|
socket.send "reload"
end
end

# Watch files and add WatcherHandler to Kemal handlers
def self.watch(files)
if Kemal.config.env == "production" || ENV["KEMAL_ENV"]? == "production"
Expand Down
8 changes: 8 additions & 0 deletions src/kemal-watcher/watcher_handler.cr
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ module Kemal
# end
# end

# Handle change when event.on_change and
# send reload message to all clients
def self.handle_change
SOCKETS.each do |socket|
socket.send "reload"
end
end

# Instead of Kemal::Handler I'm using a filter handler
# to check content_type == "text/html"
# However, http://kemalcr.com/docs/filters/ says:
Expand Down

0 comments on commit 2ddcd3f

Please sign in to comment.