Class: S5::Daemon

Inherits:
Object
  • Object
show all
Defined in:
lib/s5/daemon.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*paths, bucket_name: nil) ⇒ Daemon

Returns a new instance of Daemon.



5
6
7
8
9
10
11
# 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

Instance Attribute Details

#pidObject (readonly)

Returns the value of attribute pid.



4
5
6
# File 'lib/s5/daemon.rb', line 4

def pid
  @pid
end

Instance Method Details

#observeObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# 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

#startObject



13
14
15
16
17
# File 'lib/s5/daemon.rb', line 13

def start
  @pid = fork do
    observe
  end
end

#stopObject



19
20
21
# File 'lib/s5/daemon.rb', line 19

def stop
  Process.kill :QUIT, @pid
end