Class: Filer::Command

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

Instance Method Summary collapse

Instance Method Details

#add_directory(dir) ⇒ Object



50
51
52
53
# File 'lib/filer.rb', line 50

def add_directory(dir)
  Settings[:directories].push(dir)
  save_settings
end

#configure_s3(key, secret, bucket) ⇒ Object



67
68
69
70
71
# File 'lib/filer.rb', line 67

def configure_s3(key, secret, bucket)
  Settings[:s3_key], Settings[:s3_secret], Settings[:s3_bucket] =
    key, secret, bucket
  save_settings
end

#directoriesObject



43
44
45
46
47
# File 'lib/filer.rb', line 43

def directories
  Settings[:directories].each_with_index do |dir, i|
    puts "#{i+1}) #{dir}"
  end
end

#remove_directory(i) ⇒ Object



57
58
59
60
61
62
# File 'lib/filer.rb', line 57

def remove_directory(i)
  Settings[:directories].delete_at(i.to_i-1)
  save_settings
  puts "Updated. New directories: "
  directories
end

#search(keywords) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/filer.rb', line 74

def search(keywords)
  results = Filer::Filed.searchable(keywords).all
  if results.empty?
    puts "No results found"
    return
  end
  results.each_with_index do |r, i|
    puts "#{i+1}) #{r.key} - #{r.highlight["attachment"].join(" ... ")}" 
  end
  ix = ask("Index of file to open (q to exit):")
  return unless ix.to_i > 0 && results[ix.to_i - 1]
  s3.open_file(results[ix.to_i - 1].key.first) 
end

#start_watchingObject



32
33
34
35
# File 'lib/filer.rb', line 32

def start_watching
  watcher.daemonize!
  watcher.start!
end

#stop_watchingObject



38
39
40
# File 'lib/filer.rb', line 38

def stop_watching
  watcher.stop!
end