class S5::Daemon

Attributes

pid[R]

Public Class Methods

new(*paths, bucket_name: nil) click to toggle source
# File lib/s5/daemon.rb, line 5
def initialize(*paths, bucket_name: nil)
  @syncs = paths.map{|path|
    sync = S5::Sync.new(local_path: path, remote_bucket: bucket_name)
    sync.encrypt!
    [path, sync]
  }
end

Public Instance Methods

observe() click to toggle source
# File lib/s5/daemon.rb, line 23
def observe
  observers = @syncs.map!{|path, sync|
    sync.sync!
    [path, create_or_update(sync), delete(sync)]
  }
  FSSM.monitor do
    observers.each do |_, create_or_update, delete_proc|
      path _ do
        glob '**/*'
        create &create_or_update
        update &create_or_update
        delete &delete_proc
      end
    end
  end
end
start() click to toggle source
# File lib/s5/daemon.rb, line 13
def start
  @pid = fork do
    observe
  end
end
stop() click to toggle source
# File lib/s5/daemon.rb, line 19
def stop
  Process.kill :QUIT, @pid
end

Private Instance Methods

create_or_update(sync) click to toggle source
# File lib/s5/daemon.rb, line 41
def create_or_update(sync)
  ->(base, relative){
    sync.put(relative)
  }
end
delete(sync) click to toggle source
# File lib/s5/daemon.rb, line 47
def delete(sync)
  ->(base, relative){
    sync.delete(relative)
  }
end