crossing 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +8 -8
  2. data/bin/crossing +1 -1
  3. data/lib/crossing.rb +13 -11
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YWJiNDNlMTAyNDZkMDA2NDcyY2E2N2Y1OGRkZTgzMzE1ZTEwZmNmMw==
4
+ MTRlZDliNWZmMmM1YWI2NDk2NTMxN2Y4ZWQxNTM1N2NlMzAxZTE2MA==
5
5
  data.tar.gz: !binary |-
6
- ZGJmOWM4NTNlZGQwYTQ5ZDdjYmRlM2E1ZTk2MDAwOWJiN2RhNjdiOQ==
6
+ ZWIwN2UyZTM5YWEzMzQzNzRiOGRiNGQ2Y2QzNmE4ZWZhZTRiNjlhMA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ZWQ2YjI4YzYzNzIyNDg2OWY0OWRlMzJhYzYwMWU4YzBkYzU3MDAwOTM5OGU4
10
- MzI4Zjc4Y2Q3NmJiOTVjZDgxY2I3YzZjZWNhNDk4OTY3MWI3MDE2NjBiY2Fm
11
- ODZkZjRhOGI1ZTI4NGNkMTIxNmQyYjhhMTQyYjFmYzllMzBmNTc=
9
+ ZjAwZjVmNjNkMTg2OGI2ZDE4N2VhNWZhN2FkYmIwY2JhNWE1OTc1Y2U0NzIy
10
+ YjBiMmEyYmRiYTUyZWJiM2I3NWQ0MWFlZjlhMmQ0YjQzODUzZWE1ZmU2YWZj
11
+ NjMyYTc0MGQ4ODI5ZWYwNjkyYjIyOTA3ZmE1Yzk4MWY3Mjc3OGE=
12
12
  data.tar.gz: !binary |-
13
- NmI0ZWYwMzBlMzgzZjczYWU5ZTU2OWI2YmE0NjdmMmJiZTA3NzFlZjU3ZmNk
14
- MTgyYzk3ODI1NTdhMTI1ZWMxNjlmMGMyNDg5NDk0YmFjNmE0ZmEzYjQ0OTBk
15
- YmU3NWNlNGE3YTE4ZWRhOTgwMDNmN2I1YjlmMmY5MGJkYWI1NTg=
13
+ ZjU0OGFmM2YxODJkZmY5NGJmZGE2YTc5ZGU1NDg0YjUxODY3YWI1Njk0YWQy
14
+ ZDhkZmJiNTRhYTBmMWU3N2ZmZjE5Zjg3ODgxNzZlZTI2OThhMTU0YmMyYTQz
15
+ YTA3OGRjMzAyMWIxY2FjNzFiZjRlMTg0ODRiYTY0ZGE3YTcxMzk=
@@ -49,7 +49,7 @@ case cmd
49
49
  when 'put'
50
50
  crossing.put(cmd_opts[:bucket], cmd_opts[:file])
51
51
  when 'get'
52
- crossing.get(File, cmd_opts[:bucket], cmd_opts[:file])
52
+ crossing.get(cmd_opts[:bucket], cmd_opts[:file])
53
53
  else
54
54
  raise "unknown subcommand #{cmd}"
55
55
  end
@@ -9,26 +9,28 @@ class Crossing
9
9
  end
10
10
 
11
11
  def put(bucket, filename)
12
- begin
13
- file = File.new(filename, 'r')
14
- rescue
15
- raise CrossingFileNotFoundException, "File not found: #{filename}"
12
+ File.open(filename, 'r') do |file|
13
+ put_content(bucket, File.basename(filename), file.read)
16
14
  end
17
-
18
- put_content(bucket, filename.split('/').last, file.read)
15
+ rescue Errno::ENOENT
16
+ raise CrossingFileNotFoundException, "File not found: #{filename}"
19
17
  end
20
18
 
21
19
  def put_content(bucket, filename, content)
22
- @s3_client.put_object(bucket: bucket, key: filename.split('/').last, body: content)
20
+ @s3_client.put_object(bucket: bucket,
21
+ key: File.basename(filename),
22
+ body: content)
23
23
  end
24
24
 
25
- def get(filesystem, bucket, file)
26
- if filesystem.exist?(file)
27
- raise CrossingFileExistsException, "File #{file} already exists, will not overwrite."
25
+ def get(bucket, file)
26
+ if File.exist?(file)
27
+ raise(CrossingFileExistsException,
28
+ "File #{file} already exists, will not overwrite.")
28
29
  end
29
30
 
30
31
  content = get_content(bucket, file)
31
- filesystem.write(file, content)
32
+
33
+ File.open(file, 'wb') { |f| f.write(content) }
32
34
  end
33
35
 
34
36
  def get_content(bucket, file)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: crossing
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Ulick
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2017-02-26 00:00:00.000000000 Z
13
+ date: 2017-06-02 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: aws-sdk