jaxx 0.0.15 → 0.0.16

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NGM3Y2IyMjc4N2JlNzZjNjAzMzMyNWM3ZmRjZjc1ODM0MzFmZDVkYQ==
4
+ NWE4Njg1NTJkYjVlNzczODI4NDZiOWExZjRhMTQ5NDkyZjUzMWRjYQ==
5
5
  data.tar.gz: !binary |-
6
- Y2JkOWVlODcxNjQ3ZDdkZjc2OTljYmZlNWYzY2I4MTU1NmViZDllOQ==
6
+ MDI3NWMxNWJjODg5ZDk1MWIxNjBiNTExYTViZDRhOWQ4MjFmOTM4MA==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- YjdmNTIwMmQwN2MxYmNhMTY0ZGFhM2U1OTAyZTQ0NjkzMzM0Yzg4OTRlNzBm
10
- MmMwYTU5OWQ5NjM1NmE3ZjZmMDhhNjljZTZkNTUyY2UyYzFjODY5N2Y0NzYx
11
- YjFlYTAyNGFhODMzYzg0OWExNTFmMGFkYjcyMjNmZGY1MTdhMGU=
9
+ ZjkxNmI3M2I0YTMzZWQzNDdhMjY4MzM5MzNlZmE3ZmY4NWIxODQ4MzFmNTdj
10
+ MWU2YjdjNGM3NmVhMmNjMjI3OGMzOTcwM2JkNjQ1NWNmZDkxNjk0NzAyMmNk
11
+ MDBkODExNzUzYzVkODI5YjQwZDRiNWRiOGZlN2ZiYTQ1OTY3N2I=
12
12
  data.tar.gz: !binary |-
13
- YWNkNTJhOWYyMzU1ZjQ3ZjMwNzM0ZTZhNzVlNzExNTExMTY2NzY2NzYzNGFi
14
- MTk2ZjRkZjRkOGMxNWM3NTM0MDVhMTI0N2NhMjI0OTg1MGZmZDU1YjBlMGVj
15
- OTU2Y2I0Mzg4Zjk3MDNmYjA2MzFlNDBiMTgxNzQzNzFkMDEwMGU=
13
+ NWQ3ZmVmMmI4Y2FjYzJjZGVkOGQ5ZTEzOTZhN2JlNzhiYjJhZGUwOWExOTg0
14
+ MWE1NGQ5Yjc2NjUyZDRjZTc1YWFkN2U0NmZlMDU4YmU5MjE4NzhiMjExNGVk
15
+ OTgzOTJkOTZmY2MzY2UwMGEyYTVkNjQ1NWU3NDU5YjcyMmYzZGY=
data/lib/jaxx/cli.rb CHANGED
@@ -31,6 +31,7 @@ module Jaxx
31
31
  o.on('-f', '--file [FILE]') { |f| options['file'] = f }
32
32
  o.on('-n', '--name [name]') { |f| options['filename'] = f }
33
33
  o.on('-p', '--privacy [privacy]') { |p| options['privacy'] = p }
34
+ o.on('-r', '--retries [retries]') { |r| options['retries'] = r }
34
35
  o.on('-h', '--help') { o }
35
36
  end
36
37
  end
data/lib/jaxx/process.rb CHANGED
@@ -40,7 +40,7 @@ module Jaxx
40
40
 
41
41
  ["Unable to process transaction: ", format_errors(errs)].flatten.each do |msg|
42
42
  Jaxx.logger.write msg
43
- end and raise(RuntimeError) unless errs.empty?
43
+ end and raise(RuntimeError, errs.inspect) unless errs.empty?
44
44
 
45
45
  block.call(storage)
46
46
  end
data/lib/jaxx/upload.rb CHANGED
@@ -4,11 +4,14 @@ require 'mime/types'
4
4
  module Jaxx
5
5
  class Upload
6
6
 
7
- attr_reader :process
7
+ DEFAULT_RETRIES = 3
8
+
9
+ attr_reader :process, :retries
8
10
 
9
11
  def initialize args = {}
10
- @process = Process.new(args.merge('validations' => [:privacy, :file_exists, :file_presence]))
12
+ @process = Process.new(args.merge('validations' => [:privacy, :file_exists, :file_presence]))
11
13
  @filename = args['filename']
14
+ @retries = args['retries'] || DEFAULT_RETRIES
12
15
  end
13
16
 
14
17
  def filename
@@ -27,18 +30,45 @@ module Jaxx
27
30
 
28
31
  def execute
29
32
  process.start do |storage|
30
- directory = storage.directories.get(process.bucket)
31
- directory ||= storage.directories.create(:key => process.bucket, :public => process.public?)
33
+ dir, attempts = remote_directory(storage), 0
32
34
 
33
35
  files.each do |file, name|
34
- raise "File process failed: #{file}:#{name}" unless directory.files.create(
35
- :key => name || file,
36
- :body => File.read(file),
37
- :public => process.public?,
38
- :content_type => MIME::Types.type_for(file).last
39
- )
36
+ stat, exc = false, nil
37
+ attempts += 1
38
+
39
+ begin
40
+ stat = create_file dir, file, name
41
+ rescue => ex
42
+ exc = ex
43
+ end
44
+
45
+ if !stat and attempts >= self.retries
46
+ raise("File process failed: #{file}:#{name} : #{exc.message rescue nil}")
47
+ elsif !stat
48
+ redo
49
+ end
50
+
51
+ attempts = 0
40
52
  end
41
53
  end
54
+
55
+ end
56
+
57
+ private
58
+
59
+ def remote_directory storage
60
+ dir = storage.directories.get(process.bucket)
61
+ dir ||= storage.directories.create(:key => process.bucket, :public => process.public?)
62
+ dir
63
+ end
64
+
65
+ def create_file dir, file, name
66
+ dir.files.create(
67
+ :key => name || file,
68
+ :body => File.read(file),
69
+ :public => process.public?,
70
+ :content_type => MIME::Types.type_for(file).last
71
+ )
42
72
  end
43
73
 
44
74
  end
data/lib/jaxx/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Jaxx
2
- VERSION = "0.0.15"
2
+ VERSION = "0.0.16"
3
3
  end
@@ -1,25 +1,19 @@
1
1
  require 'spec_helper'
2
+ require 'fog/aws/models/storage/directories'
2
3
 
3
4
  module Jaxx
4
5
  describe Upload do
5
6
 
6
7
  describe "#process" do
7
- let(:args) { ({ 'access_key' => 'foo', 'access_secret' => 'bar', 'file' => File.expand_path('bar.txt', __FILE__), 'bucket' => 'temp' }) }
8
+ let(:args) { ({
9
+ 'access_key' => 'foo',
10
+ 'access_secret' => 'bar',
11
+ 'file' => File.expand_path('../bar.txt', __FILE__),
12
+ 'bucket' => 'temp'
13
+ }) }
8
14
 
9
15
  subject { described_class.new(args) }
10
16
 
11
- before :each do
12
- Fog.mock!
13
- end
14
-
15
- it "sends file to storage" do
16
- File.stub(:exist?).with(args['file']).and_return(true)
17
- File.should_receive(:read).with(args['file']).and_return("")
18
- File.should_receive(:basename).with(args['file']).and_return('bar.txt')
19
-
20
- subject.execute
21
- end
22
-
23
17
  it "defaults filename to original filename" do
24
18
  subject.filename.should eq('bar.txt')
25
19
  end
@@ -28,7 +22,37 @@ module Jaxx
28
22
  args['filename'] = 'foo.txt'
29
23
  subject.filename.should eq('foo.txt')
30
24
  end
31
- end
32
25
 
26
+ describe "sending files" do
27
+ let(:files) { double('files', merge_attributes: {}, load: {}) }
28
+
29
+ before :each do
30
+ Fog.mock!
31
+ File.stub(:exist?).with(args['file']).and_return(true)
32
+ File.stub(:basename).with(args['file']).and_return('bar.txt')
33
+ Fog::Storage::AWS::Directory.any_instance.stub(:files).and_return(files)
34
+ File.stub(:read).with(args['file']).any_number_of_times.and_return("")
35
+ end
36
+
37
+ it "to storage" do
38
+ files.should_receive(:create).and_return(true)
39
+
40
+ subject.execute
41
+ end
42
+
43
+ it "with retries" do
44
+ files.should_receive(:create).exactly(subject.retries).times.and_return(false)
45
+
46
+ -> { subject.execute }.should raise_error(RuntimeError)
47
+ end
48
+
49
+ it "with failed create" do
50
+ files.should_receive(:create).exactly(subject.retries).times.and_raise(RuntimeError)
51
+
52
+ -> { subject.execute }.should raise_error(RuntimeError)
53
+ end
54
+
55
+ end
56
+ end
33
57
  end
34
58
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jaxx
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.15
4
+ version: 0.0.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marc Watts
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-03-07 00:00:00.000000000 Z
11
+ date: 2013-03-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fog