Skip to content
This repository was archived by the owner on Sep 15, 2018. It is now read-only.

Commit be03ffe

Browse files
committed
History of uploads
1 parent d236a31 commit be03ffe

File tree

7 files changed

+64
-0
lines changed

7 files changed

+64
-0
lines changed

bin/captured

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ OptionParser.new do |opts|
1818
exit
1919
end
2020

21+
opts.on('--history', "Print History") do
22+
History.list
23+
exit
24+
end
25+
2126
opts.on('--version', "Print the version") do
2227
puts "Captured #{File.open("#{File.dirname(__FILE__)}/../VERSION", "r").read}"
2328
exit

lib/captured.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
require "#{File.dirname(__FILE__)}/captured/history"
12
require "#{File.dirname(__FILE__)}/captured/file_tracker"
23
require "#{File.dirname(__FILE__)}/captured/file_uploader"
34

lib/captured/file_uploader.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ def process_upload(file)
5050
puts "Uploaded '#{file}' to '#{remote_path}'"
5151
pbcopy remote_path
5252
growl("Upload Succeeded", "#{File.dirname(File.expand_path(__FILE__))}/../../resources/green_check.png")
53+
History.append(file, remote_path)
5354
rescue => e
5455
puts e
5556
puts e.backtrace

lib/captured/history.rb

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
require 'shellwords'
2+
3+
class History
4+
5+
def self.file_path
6+
"#{ENV['HOME']}/.captured_history"
7+
end
8+
9+
def self.time_stamp
10+
DateTime.now.strftime("%m/%d/%Y-%I:%M%p")
11+
end
12+
13+
def self.append(original_name, remote_path)
14+
File.open(History.file_path, 'a') do |f|
15+
f.puts(History.format_line(original_name, remote_path))
16+
end
17+
end
18+
19+
def self.format_line(original_name, remote_path)
20+
"#{History.time_stamp} \"#{original_name}\" #{remote_path}"
21+
end
22+
23+
def self.list
24+
if File.exists? History.file_path
25+
File.open(History.file_path).each do |line|
26+
puts line
27+
end
28+
else
29+
puts "You ain't got no history yet"
30+
end
31+
end
32+
end

spec/fixtures/history

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
01/11/2010 02:47PM original_file remote_path
2+
01/11/2010 02:48PM original_file remote_path
3+
01/11/2010 02:49PM original_file remote_path

spec/history_spec.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2+
3+
describe "History" do
4+
before(:each) do
5+
@date_time = mock(DateTime)
6+
@date_time.stub!(:strftime).and_return("01/11/2010 02:48PM")
7+
DateTime.stub!(:now).and_return(@date_time)
8+
History.stub!(:file_path).and_return("#{File.dirname(__FILE__)}/fixtures/history")
9+
end
10+
11+
it "should format a line" do
12+
line = History.format_line("original_name", "remote_path")
13+
line.should == "01/11/2010 02:48PM original_name remote_path"
14+
end
15+
16+
it "should list the history" do
17+
History.should respond_to(:list)
18+
end
19+
end
20+

spec/spec_helper.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
66
require 'captured'
77

8+
CONFIG = YAML.load_file("#{ENV['HOME']}/.captured.yml")
9+
810
Spec::Runner.configure do |config|
911

1012
end

0 commit comments

Comments
 (0)