imw 0.2.15 → 0.2.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.15
1
+ 0.2.16
@@ -172,7 +172,7 @@ module IMW
172
172
  # @return [String]
173
173
  def snippet
174
174
  returning([]) do |snip|
175
- io.read(1024).bytes.each do |byte|
175
+ (io.read(1024) || '').bytes.each do |byte|
176
176
  # CR LF SPACE ~
177
177
  snip << byte.chr if byte == 13 || byte == 10 || byte >= 32 && byte <= 126
178
178
  end
@@ -33,17 +33,11 @@ module IMW
33
33
  IMW::Schemes::S3.get(self, new_uri)
34
34
  end
35
35
 
36
- # The AWS::S3::S3Object corresponding to this resource.
37
- def s3_object
38
- ::IMW::Schemes::S3.make_connection!
39
- @s3_object ||= AWS::S3::S3Object.new(path, :bucket => bucket)
40
- end
41
-
42
36
  # Does this resource exist on S3?
43
37
  #
44
38
  # @return [true, false]
45
39
  def exist?
46
- s3_object.exists?
40
+ AWS::S3::S3Object.exists?(raw_path, bucket)
47
41
  end
48
42
  alias_method :exists?, :exist?
49
43
 
@@ -51,7 +45,7 @@ module IMW
51
45
  #
52
46
  # @return [IMW::Resource] the deleted object
53
47
  def rm
54
- s3_object.delete
48
+ AWS::S3::S3Object.delete(raw_path, bucket)
55
49
  end
56
50
  alias_method :rm!, :rm
57
51
 
@@ -70,7 +64,7 @@ module IMW
70
64
  #
71
65
  # @return [String]
72
66
  def read
73
- s3_object.value
67
+ AWS::S3::S3Object.value(raw_path, bucket)
74
68
  end
75
69
 
76
70
  # Store +source+ into +destination+.
@@ -83,7 +77,7 @@ module IMW
83
77
  destintation = IMW.open(destination)
84
78
  raise IMW::ArgumentError.new("destination must be on S3 -- #{destination} given") unless destination.on_s3?
85
79
  make_connection!
86
- AWS::S3::S3Object.store(destination.path, source.io, destination.bucket)
80
+ AWS::S3::S3Object.store(destination.raw_path, source.io, destination.bucket)
87
81
  destination
88
82
  end
89
83
 
@@ -97,7 +91,7 @@ module IMW
97
91
  destination = IMW.open!(destination)
98
92
  raise IMW::ArgumentError.new("source must be on S3 -- #{source} given") unless source.on_s3?
99
93
  make_connection!
100
- AWS::S3::S3Object.stream(source.path, source.bucket) do |chunk|
94
+ AWS::S3::S3Object.stream(source.raw_path, source.bucket) do |chunk|
101
95
  destination.write(chunk)
102
96
  end
103
97
  destination.close
@@ -114,7 +108,7 @@ module IMW
114
108
  destination = IMW.open(destination)
115
109
  raise IMW::PathError.new("Bucket names must be non-blank and match to 'copy'") unless source.bucket.present? && destination.bucket.present? && source.bucket == destination.bucket
116
110
  make_connection!
117
- AWS::S3::Object.copy(source.path, destination.path, destination.bucket)
111
+ AWS::S3::Object.copy(source.raw_path, destination.raw_path, destination.bucket)
118
112
  destination
119
113
  end
120
114
 
@@ -108,6 +108,16 @@ module IMW
108
108
  uri.class.new(uri_args)
109
109
  end
110
110
 
111
+ # Return the path complete with query string and fragment.
112
+ #
113
+ # @return [String]
114
+ def raw_path
115
+ p = uri.path
116
+ p += "?#{uri.query}" unless uri.query.nil?
117
+ p += "##{uri.fragment}" unless uri.fragment.nil?
118
+ p
119
+ end
120
+
111
121
  def to_s
112
122
  uri.to_s
113
123
  end
@@ -19,5 +19,14 @@ describe IMW::Schemes::S3 do
19
19
  @resource.join('a', 'b/c').to_s.should == File.join(@resource.to_s, 'a/b/c')
20
20
  end
21
21
  end
22
-
22
+
23
+ describe "reading S3 files" do
24
+ before { IMW::Schemes::S3.make_connection! }
25
+ ['file', 'file with spaces', 'file with # fragment'].each do |f|
26
+ it "can read a file named '#{f}' from S3" do
27
+ IMW::Resource.new("s3://imw.infinitemonkeys.info/spec/schemes/s3/#{f}").read.chomp.should == 'ok'
28
+ end
29
+ end
30
+ end
31
+
23
32
  end
@@ -50,6 +50,12 @@ describe IMW::Utils::HasURI do
50
50
  new_obj('/path/to/something').stripped_uri.to_s.should == '/path/to/something'
51
51
  new_obj('http://user:pass@example.com:8080/path/to/some/script.php?param=value#frag').stripped_uri.to_s.should == 'http://user:pass@example.com:8080/path/to/some/script.php'
52
52
  end
53
-
53
+
54
+ it "should be able to return raw paths" do
55
+ new_obj('s3://bucket/crazy url with # some dumb naming convention').raw_path.should == '/crazy url with # some dumb naming convention'
56
+ new_obj('s3://bucket/crazy url with ?some dumb naming convention').raw_path.should == '/crazy url with ?some dumb naming convention'
57
+ new_obj('s3://bucket/crazy url with ?some dumb naming #convention').raw_path.should == '/crazy url with ?some dumb naming #convention'
58
+ new_obj('s3://bucket/crazy url with #some dumb naming ?convention').raw_path.should == '/crazy url with #some dumb naming ?convention'
59
+ end
54
60
 
55
61
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: imw
3
3
  version: !ruby/object:Gem::Version
4
- hash: 9
4
+ hash: 55
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 15
10
- version: 0.2.15
9
+ - 16
10
+ version: 0.2.16
11
11
  platform: ruby
12
12
  authors:
13
13
  - Dhruv Bansal
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2010-12-14 00:00:00 -06:00
19
+ date: 2010-12-21 00:00:00 -06:00
20
20
  default_executable:
21
21
  dependencies: []
22
22