rubydora 0.5.12 → 0.5.13

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.5.12
1
+ 0.5.13
@@ -21,7 +21,7 @@ module Rubydora
21
21
  DS_DEFAULT_ATTRIBUTES = { :controlGroup => 'M', :dsState => 'A', :versionable => true }
22
22
 
23
23
  define_attribute_methods DS_ATTRIBUTES.keys
24
-
24
+
25
25
  # accessors for datastream attributes
26
26
  DS_ATTRIBUTES.each do |attribute, profile_name|
27
27
  define_method attribute.to_s do
@@ -29,9 +29,9 @@ module Rubydora
29
29
  if instance_variable_defined?(var)
30
30
  instance_variable_get var
31
31
  elsif profile.has_key? profile_name.to_s
32
- profile[profile_name.to_s]
32
+ profile[profile_name.to_s]
33
33
  else
34
- DS_DEFAULT_ATTRIBUTES[attribute.to_sym]
34
+ default_attributes[attribute.to_sym]
35
35
  end
36
36
  end
37
37
 
@@ -47,7 +47,7 @@ module Rubydora
47
47
  DS_READONLY_ATTRIBUTES.each do |attribute|
48
48
  class_eval %Q{
49
49
  def #{attribute.to_s}
50
- @#{attribute} || profile['#{attribute.to_s}'] || DS_DEFAULT_ATTRIBUTES[:#{attribute}]
50
+ @#{attribute} || profile['#{attribute.to_s}'] || default_attributes[:#{attribute}]
51
51
  end
52
52
  }
53
53
 
@@ -78,6 +78,18 @@ module Rubydora
78
78
  return self.class.new(@digital_object, @dsid, @options.merge(:asOfDateTime => asOfDateTime))
79
79
  end
80
80
 
81
+ def self.default_attributes
82
+ DS_DEFAULT_ATTRIBUTES
83
+ end
84
+
85
+ def default_attributes
86
+ @default_attributes ||= self.class.default_attributes
87
+ end
88
+
89
+ def default_attributes= attributes
90
+ @default_attributes = default_attributes.merge attributes
91
+ end
92
+
81
93
  ##
82
94
  # Initialize a Rubydora::Datastream object, which may or
83
95
  # may not already exist in the datastore.
@@ -87,11 +99,12 @@ module Rubydora
87
99
  # @param [Rubydora::DigitalObject]
88
100
  # @param [String] Datastream ID
89
101
  # @param [Hash] default attribute values (used esp. for creating new datastreams)
90
- def initialize digital_object, dsid, options = {}
102
+ def initialize digital_object, dsid, options = {}, default_instance_attributes = {}
91
103
  _run_initialize_callbacks do
92
104
  @digital_object = digital_object
93
105
  @dsid = dsid
94
106
  @options = options
107
+ @default_attributes = default_attributes.merge(default_instance_attributes)
95
108
  options.each do |key, value|
96
109
  self.send(:"#{key}=", value)
97
110
  end
@@ -239,6 +252,10 @@ module Rubydora
239
252
  end
240
253
  end
241
254
 
255
+ def datastream_will_change!
256
+ attribute_will_change! :profile
257
+ end
258
+
242
259
  protected
243
260
  # datastream parameters
244
261
  # @return [Hash]
@@ -256,7 +273,7 @@ module Rubydora
256
273
  # default datastream parameters
257
274
  # @return [Hash]
258
275
  def default_api_params
259
- return DS_DEFAULT_ATTRIBUTES.dup if new?
276
+ return default_attributes.dup if new?
260
277
  {}
261
278
  end
262
279
 
@@ -18,10 +18,15 @@ describe Rubydora::Datastream do
18
18
  @datastream.new?.should == true
19
19
  end
20
20
 
21
- it "should be dirty" do
21
+ it "should not be dirty" do
22
22
  @datastream.changed?.should == false
23
23
  end
24
24
 
25
+ it "should be dirty if datastream_will_change! is called" do
26
+ @datastream.datastream_will_change!
27
+ @datastream.changed?.should == true
28
+ end
29
+
25
30
  it "should have default values" do
26
31
  @datastream.controlGroup == "M"
27
32
  @datastream.dsState.should == "A"
@@ -29,6 +34,13 @@ describe Rubydora::Datastream do
29
34
  @datastream.changed.should be_empty
30
35
  end
31
36
 
37
+ it "should allow default values to by specified later" do
38
+ @datastream.dsState = 'A'
39
+ @datastream.default_attributes = { :controlGroup => 'E', :dsState => 'I' }
40
+ @datastream.controlGroup.should == 'E'
41
+ @datastream.dsState.should == 'A'
42
+ end
43
+
32
44
  it "should allow versionable to be set to false" do
33
45
  @datastream.versionable = false
34
46
  @datastream.versionable.should be_false
@@ -340,7 +352,8 @@ describe Rubydora::Datastream do
340
352
  end
341
353
 
342
354
  it "should fall-back to the set of default attributes" do
343
- Rubydora::Datastream::DS_DEFAULT_ATTRIBUTES.should_receive(:[]).with(method.to_sym) { 'zxcv'}
355
+ mock_attr = { method.to_sym => 'zxcv' }
356
+ subject.should_receive(:default_attributes).and_return(mock_attr)
344
357
  subject.send(method).should == 'zxcv'
345
358
  end
346
359
  end
@@ -382,7 +395,8 @@ describe Rubydora::Datastream do
382
395
  end
383
396
 
384
397
  it "should fall-back to the set of default attributes" do
385
- Rubydora::Datastream::DS_DEFAULT_ATTRIBUTES.should_receive(:[]).with(method.to_sym) { 'zxcv'}
398
+ mock_attr = { method.to_sym => 'zxcv' }
399
+ subject.should_receive(:default_attributes).and_return(mock_attr)
386
400
  subject.send(method).should == 'zxcv'
387
401
  end
388
402
  end
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: 0.5.12
4
+ version: 0.5.13
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-20 00:00:00.000000000 Z
12
+ date: 2012-07-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: fastercsv
@@ -312,7 +312,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
312
312
  version: '0'
313
313
  segments:
314
314
  - 0
315
- hash: -1776488300066485637
315
+ hash: -2331369473702813867
316
316
  required_rubygems_version: !ruby/object:Gem::Requirement
317
317
  none: false
318
318
  requirements:
@@ -321,7 +321,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
321
321
  version: '0'
322
322
  segments:
323
323
  - 0
324
- hash: -1776488300066485637
324
+ hash: -2331369473702813867
325
325
  requirements: []
326
326
  rubyforge_project:
327
327
  rubygems_version: 1.8.24