Skip to content

Commit

Permalink
Add force polling option (-o) the "wagon serve" command
Browse files Browse the repository at this point in the history
  • Loading branch information
uxtronaut committed Feb 19, 2015
1 parent b31fe14 commit 1ddf3c0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/locomotive/wagon.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def self.serve(path, options)
end

# listen_thread = Thread.new do
Locomotive::Wagon::Listen.instance.start(reader) if use_listen
Locomotive::Wagon::Listen.instance.start(reader, options) if use_listen

server.start
# end
Expand Down
6 changes: 6 additions & 0 deletions lib/locomotive/wagon/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -262,11 +262,17 @@ def list_templates
method_option :port, aliases: '-p', type: 'string', default: '3333', desc: 'The port of the Thin server'
method_option :daemonize, aliases: '-d', type: 'boolean', default: false, desc: 'Run daemonized Thin server in the background'
method_option :live_reload_port, aliases: '-l', type: 'string', default: false, desc: 'Include the Livereload javascript in each page'
method_option :force_polling, aliases: '-o', type: 'boolean', default: false, desc: 'Force polling of files for reload'
method_option :force, aliases: '-f', type: 'boolean', default: false, desc: 'Stop the current daemonized Thin server if found before starting a new one'
method_option :verbose, aliases: '-v', type: 'boolean', default: false, desc: 'display the full error stack trace if an error occurs'
def serve(path = '.')
parent_pid = Process.pid
force_color_if_asked(options)

if options[:force_polling]
say "Listener polling is on."
end

if check_path!(path)
begin
Locomotive::Wagon.serve(path, options)
Expand Down
10 changes: 5 additions & 5 deletions lib/locomotive/wagon/listen.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ def self.instance
@@instance = new
end

def start(reader)
def start(reader, options)
@reader = reader

self.definitions.each do |definition|
self.apply(definition)
self.apply(definition, options)
end
end

Expand All @@ -29,7 +29,7 @@ def definitions

protected

def apply(definition)
def apply(definition, options)
reloader = Proc.new do |modified, added, removed|
resources = [*definition.last]
names = resources.map { |n| "\"#{n}\"" }.join(', ')
Expand All @@ -49,7 +49,7 @@ def apply(definition)
path = File.join(self.reader.mounting_point.path, definition.first)
path = File.expand_path(path)

listener = ::Listen.to(path, {only: filter, force_polling: true}, &reloader)
listener = ::Listen.to(path, {only: filter, force_polling: options[:force_polling]}, &reloader)

# non blocking listener
listener.start
Expand All @@ -62,4 +62,4 @@ def relative_path(path)

end

end
end

0 comments on commit 1ddf3c0

Please sign in to comment.