Class: Webby::AutoBuilder
- Inherits:
-
Object
- Object
- Webby::AutoBuilder
- Defined in:
- lib/webby/auto_builder.rb
Overview
The AutoBuilder class is used to monitor the content and layouts folders and to compile the resource files only when they are modified. If a layout is modified, then all resources that depend upon the layout are compiled.
Class Method Summary collapse
-
.run ⇒ Object
call-seq: AutoBuilder.run.
Instance Method Summary collapse
-
#initialize ⇒ AutoBuilder
constructor
call-seq: AutoBuilder.new.
-
#run ⇒ Object
call-seq: run.
-
#update(*events) ⇒ Object
call-seq: update( *events ).
Constructor Details
#initialize ⇒ AutoBuilder
29 30 31 32 33 34 35 36 37 |
# File 'lib/webby/auto_builder.rb', line 29 def initialize @watcher = DirectoryWatcher.new '.', :interval => 2 @watcher.add_observer self glob = [] glob << File.join(::Webby.config['layout_dir'], '**', '*') glob << File.join(::Webby.config['content_dir'], '**', '*') @watcher.glob = glob end |
Class Method Details
.run ⇒ Object
call-seq:
AutoBuilder.run
Creates a new AutoBuilder and sets it running. This method will only return when the user presses Ctrl-C.
20 21 22 |
# File 'lib/webby/auto_builder.rb', line 20 def self.run self.new.run end |
Instance Method Details
#run ⇒ Object
call-seq:
run
Starts the DirectoryWatcher running and waits till the user presses Ctrl-C to stop the watcher thread.
63 64 65 66 67 68 69 70 |
# File 'lib/webby/auto_builder.rb', line 63 def run puts '-- starting autobuild (Ctrl-C to stop)' Signal.trap('INT') {@watcher.stop} @watcher.start @watcher.join end |
#update(*events) ⇒ Object
call-seq:
update( *events )
The update method is called by the DirectoryWatcher when files have been modified, added, or deleted. An array of events is passed to his method, and each event contains the event type and the path to the file.
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/webby/auto_builder.rb', line 46 def update( *events ) ary = events.find_all {|evt| evt.type != :removed} return if ary.empty? print '- started at ' puts Time.now.strftime('%H:%M:%S') Builder.run rescue => err puts err. end |