Class: Captured

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

Class Method Summary collapse

Class Method Details

.config_fileObject



5
6
7
# File 'lib/captured.rb', line 5

def self.config_file
  "#{ENV['HOME']}/.captured.yml" 
end

.guess_watch_pathObject



9
10
11
12
13
14
15
16
17
18
# File 'lib/captured.rb', line 9

def self.guess_watch_path
  if `sw_vers | awk '/ProductVersion:/ {print $2}'` =~ /10\.5/
    "Picture**.png"
  else
    "Screenshot**.png"
  end
rescue => e
  puts e
  "Screenshot**.png"
end

.run_and_watch!(options) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/captured.rb', line 30

def self.run_and_watch!(options)
  require 'captured/fs_events'
  watch_path = options[:watch_path] || "#{ENV['HOME']}/Desktop/"
  tracker = FileTracker.new(options)
  tracker.scan([desktop_dir], :existing)
  e = FSEvents.new(watch_path)
  e.run do |paths|
    tracker.scan paths, :pending
    tracker.each_pending do |file|
      FileUploader.upload(file, options)
      tracker.mark_processed(file)
    end
  end
end

.run_once!(options) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/captured.rb', line 20

def self.run_once!(options)
  watch_path = options[:watch_path] || "#{ENV['HOME']}/Desktop/"
  Dir["#{watch_path}#{options[:watch_pattern]}"].each do |file|
    if (File.mtime(file).to_i > (Time.now.to_i-10))
      puts "#{file} is new"
      FileUploader.upload(file, options)
    end
  end
end