class Zine::Watcher
Watch files for changes
Attributes
delete_array[R]
listener_array[RW]
upload_array[R]
Public Class Methods
new(posts_and_headlines, build_directory, source_directory)
click to toggle source
# File lib/zine/watcher.rb, line 10 def initialize(posts_and_headlines, build_directory, source_directory) @posts_and_headlines = posts_and_headlines @build_directory = File.join Dir.pwd, build_directory @source_directory = File.join Dir.pwd, source_directory @upload_array = [] @delete_array = [] @listener_array = [] end
Public Instance Methods
notice(file_name)
click to toggle source
# File lib/zine/watcher.rb, line 19 def notice(file_name) @upload_array << file_name end
start()
click to toggle source
Build a delete list & an upload list for SSH from changes in build, & rebuild & reload on changes in source
# File lib/zine/watcher.rb, line 25 def start watch_build_dir watch_source_dir end
Private Instance Methods
on_build_change(path_string_array)
click to toggle source
# File lib/zine/watcher.rb, line 32 def on_build_change(path_string_array) path_string_array.each do |str| rel_path = rel_path_from_build_dir str @upload_array << rel_path end end
on_build_delete(path_string_array)
click to toggle source
# File lib/zine/watcher.rb, line 39 def on_build_delete(path_string_array) path_string_array.each do |str| rel_path = rel_path_from_build_dir str @delete_array << rel_path # @upload_array.delete rel_path end end
on_source_change(path)
click to toggle source
rebuild the file, and the headline files & tags TODO: moves within the watched directory won't delete the old location
# File lib/zine/watcher.rb, line 54 def on_source_change(path) path.each do |file| if !file.nil? && (file =~ /^.+\.md$/).nil? @posts_and_headlines.preview_straight_copy file else @posts_and_headlines.preview_rebuild file end end end
on_source_delete(path)
click to toggle source
delete build file from posts, then posts entry rebuild the headline files… and the tags…
# File lib/zine/watcher.rb, line 66 def on_source_delete(path) path.each do |file| if !file.nil? && (file =~ /^.+\.md$/).nil? @posts_and_headlines.preview_straight_delete file else @posts_and_headlines.preview_delete file end end end
rel_path_from_build_dir(path)
click to toggle source
# File lib/zine/watcher.rb, line 47 def rel_path_from_build_dir(path) full = Pathname(path) full.relative_path_from(Pathname(@build_directory)) end
watch_build_dir()
click to toggle source
# File lib/zine/watcher.rb, line 76 def watch_build_dir listener = Listen.to(@build_directory) do |modified, added, removed| on_build_change modified unless modified.empty? on_build_change added unless added.empty? on_build_delete removed unless removed.empty? end listener.start @listener_array << listener end
watch_source_dir()
click to toggle source
# File lib/zine/watcher.rb, line 86 def watch_source_dir listener = Listen.to(@source_directory) do |modified, added, removed| on_source_change modified unless modified.empty? on_source_change added unless added.empty? on_source_delete removed unless removed.empty? end listener.start @listener_array << listener end