Class: Themebox::Cli

Inherits:
Thor
  • Object
show all
Defined in:
lib/themebox/cli.rb

Instance Method Summary collapse

Instance Method Details

#watchObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/themebox/cli.rb', line 9

def watch
  token = File.read(File.expand_path("~/.themebox")).strip
  themebox = ::Themebox::Client.new(token)
  basepath = Pathname.new( File.expand_path('.') )

  relative_path_from = Proc.new do |absolute_path|
    Pathname.new(absolute_path).relative_path_from(basepath).to_s
  end

  puts "Listening to #{basepath}"

  listener = Listen.to('.', force_polling: true) do |modified, added, removed|
    changed = modified + added

    changed.each do |absolute_path|
      file = File.new(absolute_path)
      themebox.upload_file(relative_path_from.call(absolute_path), file)
    end

    removed.each do |absolute_path|
      themebox.delete_file(relative_path_from.call(absolute_path))
    end
  end

  listener.start
  sleep
end