rubydora 1.0.2 → 1.1.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.
Files changed (3) hide show
  1. data/VERSION +1 -1
  2. data/lib/rubydora/datastream.rb +25 -6
  3. metadata +3 -3
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.2
1
+ 1.1.0
@@ -126,18 +126,22 @@ module Rubydora
126
126
  def content
127
127
  return @content if new?
128
128
 
129
- begin
129
+ @content ||= datastream_content
130
+
131
+ content = @content.read and @content.rewind if @content.kind_of? IO
132
+ content ||= @content
133
+ end
134
+ alias_method :read, :content
135
+
136
+ def datastream_content
137
+ @datastream_content ||=begin
130
138
  options = { :pid => pid, :dsid => dsid }
131
139
  options[:asOfDateTime] = asOfDateTime if asOfDateTime
132
140
 
133
- @content ||= repository.datastream_dissemination options
141
+ repository.datastream_dissemination options
134
142
  rescue RestClient::ResourceNotFound
135
143
  end
136
-
137
- content = @content.read and @content.rewind if @content.kind_of? IO
138
- content ||= @content
139
144
  end
140
- alias_method :read, :content
141
145
 
142
146
  # Get the URL for the datastream content
143
147
  # @return [String]
@@ -162,6 +166,19 @@ module Rubydora
162
166
  changed_attributes['content'] = nil
163
167
  end
164
168
 
169
+ def content_changed?
170
+ # we have content
171
+ return true if new? # new datastreams must have content
172
+
173
+ # compare content against the original datastream content, if it is conventient
174
+ return true if datastream_content_loaded? and has_content? and content != datastream_content
175
+ super
176
+ end
177
+
178
+ def datastream_content_loaded?
179
+ instance_variable_defined?(:@datastream_content)
180
+ end
181
+
165
182
  def has_content?
166
183
  # persisted objects are required to have content
167
184
  return true unless new?
@@ -290,6 +307,7 @@ module Rubydora
290
307
  def to_api_params
291
308
  h = default_api_params
292
309
  valid_changed_attributes = changes.keys.map { |x| x.to_sym }.select { |x| DS_ATTRIBUTES.key? x }
310
+ valid_changed_attributes += [:content] if content_changed? and !valid_changed_attributes.include? :content
293
311
  ## if we don't provide a mimeType, application/octet-stream will be used instead
294
312
  (valid_changed_attributes | [:mimeType]).each do |attribute|
295
313
  h[attribute.to_sym] = send(attribute) unless send(attribute).nil?
@@ -310,6 +328,7 @@ module Rubydora
310
328
  def reset_profile_attributes
311
329
  @profile = nil
312
330
  @profile_xml = nil
331
+ @datastream_content = nil
313
332
  @changed_attributes = {}
314
333
  end
315
334
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubydora
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -286,7 +286,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
286
286
  version: '0'
287
287
  segments:
288
288
  - 0
289
- hash: -582924763535937155
289
+ hash: 2972472270230562990
290
290
  required_rubygems_version: !ruby/object:Gem::Requirement
291
291
  none: false
292
292
  requirements:
@@ -295,7 +295,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
295
295
  version: '0'
296
296
  segments:
297
297
  - 0
298
- hash: -582924763535937155
298
+ hash: 2972472270230562990
299
299
  requirements: []
300
300
  rubyforge_project:
301
301
  rubygems_version: 1.8.23