rcap 1.2.4 → 1.3.0

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/CHANGELOG.rdoc CHANGED
@@ -1,5 +1,11 @@
1
1
  = Change Log
2
2
 
3
+ === 1.3.0 - 15 December 2011
4
+
5
+ * Removed Resource#deref_uri= in 1.1 and 1.2 API.
6
+ * Added Resource#calculate_size_and_hash to calculate size and SHA1 hash of deref_uri if present
7
+ * Hash and size of referenced URI are only calculated on an explicit call to Resource#dereference_uri!
8
+
3
9
  === 1.2.4 - 4 December 2011
4
10
 
5
11
  * Fixed parsing bug when creating Parameter and subclasses from XML
data/README.rdoc CHANGED
@@ -8,7 +8,7 @@ RCAP currently supports CAP 1.0, 1.1 and 1.2.
8
8
 
9
9
  == Version
10
10
 
11
- 1.2.3
11
+ 1.3.0
12
12
 
13
13
  == Dependencies
14
14
 
@@ -120,7 +120,7 @@ Will produce the following output:
120
120
 
121
121
  All RCAP classes include the Validation module.
122
122
 
123
- A full spec suite using {RSpec}[http://www.rspec.info] was used to test the validations and currently numbers over 600 tests.
123
+ A full spec suite using {RSpec}[http://www.rspec.info] was used to test the validations and currently numbers over 1000 tests.
124
124
 
125
125
  === Exporting an Alert
126
126
 
@@ -14,7 +14,7 @@ module RCAP
14
14
  # Resource location
15
15
  attr_accessor( :uri )
16
16
  # Dereferenced URI - contents of URI Base64 encoded
17
- attr_reader( :deref_uri )
17
+ attr_accessor( :deref_uri )
18
18
  # SHA-1 hash of contents of resource
19
19
  attr_accessor( :digest )
20
20
 
@@ -77,13 +77,6 @@ module RCAP
77
77
  self.resource_desc
78
78
  end
79
79
 
80
- # Sets the deref_uri. The SHA digest and size are also calculated and set.
81
- def deref_uri=( value )
82
- @deref_uri = value
83
- self.digest = Digest::SHA1.hexdigest( @deref_uri )
84
- self.size = @deref_uri.bytesize
85
- end
86
-
87
80
  # Retrieves the content at uri and stores it in deref_uri as Base64 encoded text. It will also
88
81
  # calculate the digest on the encoded data using SHA1 and set the size.
89
82
  #
@@ -91,7 +84,15 @@ module RCAP
91
84
  # to open and read the content.
92
85
  def dereference_uri!
93
86
  content = URI.parse( self.uri ).read
94
- self.deref_uri = Base64.encode64( content )
87
+ @deref_uri = Base64.encode64( content )
88
+ self.calculate_hash_and_size
89
+ end
90
+
91
+ def calculate_hash_and_size
92
+ if @deref_uri
93
+ @digest = Digest::SHA1.hexdigest( @deref_uri )
94
+ @size = @deref_uri.bytesize
95
+ end
95
96
  end
96
97
 
97
98
  def self.from_xml_element( resource_xml_element ) # :nodoc:
@@ -15,7 +15,7 @@ module RCAP
15
15
  # Resource location
16
16
  attr_accessor( :uri )
17
17
  # Dereferenced URI - contents of URI Base64 encoded
18
- attr_reader( :deref_uri )
18
+ attr_accessor( :deref_uri )
19
19
  # SHA-1 hash of contents of resource
20
20
  attr_accessor( :digest )
21
21
 
@@ -79,13 +79,6 @@ module RCAP
79
79
  self.resource_desc
80
80
  end
81
81
 
82
- # Sets the deref_uri. The SHA digest and size are also calculated and set.
83
- def deref_uri=( value )
84
- @deref_uri = value
85
- self.digest = Digest::SHA1.hexdigest( @deref_uri )
86
- self.size = @deref_uri.bytesize
87
- end
88
-
89
82
  # Retrieves the content at uri and stores it in deref_uri as Base64 encoded text. It will also
90
83
  # calculate the digest on the encoded data using SHA1 and set the size.
91
84
  #
@@ -93,7 +86,15 @@ module RCAP
93
86
  # to open and read the content.
94
87
  def dereference_uri!
95
88
  content = URI.parse( self.uri ).read
96
- self.deref_uri = Base64.encode64( content )
89
+ @deref_uri = Base64.encode64( content )
90
+ self.calculate_hash_and_size
91
+ end
92
+
93
+ def calculate_hash_and_size
94
+ if @deref_uri
95
+ @digest = Digest::SHA1.hexdigest( @deref_uri )
96
+ @size = @deref_uri.bytesize
97
+ end
97
98
  end
98
99
 
99
100
  def self.from_xml_element( resource_xml_element ) # :nodoc:
data/lib/rcap/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module RCAP
2
- VERSION = '1.2.4'
2
+ VERSION = '1.3.0'
3
3
  end
@@ -182,4 +182,22 @@ describe( RCAP::CAP_1_1::Resource ) do
182
182
  end
183
183
  end
184
184
  end
185
+
186
+ context( 'with a dereferenced URI' ) do
187
+ before( :each ) do
188
+ @content = "1,2\n3,4"
189
+ @encoded_content = Base64.encode64( @content )
190
+ @resource = RCAP::CAP_1_1::Resource.new( :resource_desc => 'Resource Description', :mime_type => 'text/csv', :uri => 'http://tempuri.org/resource.csv', :deref_uri => @encoded_content )
191
+ end
192
+
193
+ describe( '#calculate_hash_and_size' ) do
194
+ it( 'should generate the correct SHA1 hash' ) do
195
+ lambda{ @resource.calculate_hash_and_size }.should( change( @resource, :digest ).to( Digest::SHA1.hexdigest( @encoded_content )))
196
+ end
197
+
198
+ it( 'should set the size in bytes' ) do
199
+ lambda{ @resource.calculate_hash_and_size }.should( change( @resource, :size ).to( @encoded_content.bytesize ))
200
+ end
201
+ end
202
+ end
185
203
  end
@@ -187,4 +187,22 @@ describe( RCAP::CAP_1_2::Resource ) do
187
187
  end
188
188
  end
189
189
  end
190
+
191
+ context( 'with a dereferenced URI' ) do
192
+ before( :each ) do
193
+ @content = "1,2\n3,4"
194
+ @encoded_content = Base64.encode64( @content )
195
+ @resource = RCAP::CAP_1_1::Resource.new( :resource_desc => 'Resource Description', :mime_type => 'text/csv', :uri => 'http://tempuri.org/resource.csv', :deref_uri => @encoded_content )
196
+ end
197
+
198
+ describe( '#calculate_hash_and_size' ) do
199
+ it( 'should generate the correct SHA1 hash' ) do
200
+ lambda{ @resource.calculate_hash_and_size }.should( change( @resource, :digest ).to( Digest::SHA1.hexdigest( @encoded_content )))
201
+ end
202
+
203
+ it( 'should set the size in bytes' ) do
204
+ lambda{ @resource.calculate_hash_and_size }.should( change( @resource, :size ).to( @encoded_content.bytesize ))
205
+ end
206
+ end
207
+ end
190
208
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rcap
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
- - 2
9
- - 4
10
- version: 1.2.4
8
+ - 3
9
+ - 0
10
+ version: 1.3.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Farrel Lifson
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-12-03 00:00:00 Z
18
+ date: 2011-12-15 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: assistance