rubydora 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.1
1
+ 0.2.2
@@ -16,6 +16,7 @@ module Rubydora
16
16
 
17
17
  # mapping datastream attributes (and api parameters) to datastream profile names
18
18
  DS_ATTRIBUTES = {:controlGroup => :dsControlGroup, :dsLocation => :dsLocation, :altIDs => nil, :dsLabel => :dsLabel, :versionable => :dsVersionable, :dsState => :dsState, :formatURI => :dsFormatURI, :checksumType => :dsChecksumType, :checksum => :dsChecksum, :mimeType => :dsMIME, :logMessage => nil, :ignoreContent => nil, :lastModifiedDate => nil, :content => nil}
19
+ DS_DEFAULT_ATTRIBUTES = { :controlGroup => 'M', :dsState => 'A', :checksumType => 'DISABLED', :versionable => true }
19
20
 
20
21
  define_attribute_methods DS_ATTRIBUTES.keys
21
22
 
@@ -23,7 +24,7 @@ module Rubydora
23
24
  DS_ATTRIBUTES.each do |attribute, profile_name|
24
25
  class_eval %Q{
25
26
  def #{attribute.to_s}
26
- (@#{attribute} || profile['#{profile_name.to_s}']).to_s
27
+ @#{attribute} || profile['#{profile_name.to_s}'] || DS_DEFAULT_ATTRIBUTES[:#{attribute}]
27
28
  end
28
29
 
29
30
  def #{attribute.to_s}= val
@@ -155,8 +156,8 @@ module Rubydora
155
156
  # @return [Hash]
156
157
  def to_api_params
157
158
  h = default_api_params
158
- DS_ATTRIBUTES.each do |attribute, profile_name|
159
- h[attribute] = instance_variable_get("@#{attribute.to_s}") unless instance_variable_get("@#{attribute.to_s}").nil?
159
+ changes.keys.map { |x| x.to_sym }.select { |x| DS_ATTRIBUTES.key? x }.each do |attribute|
160
+ h[attribute] = send(attribute) if send(attribute)
160
161
  end
161
162
 
162
163
  h
@@ -165,7 +166,8 @@ module Rubydora
165
166
  # default datastream parameters
166
167
  # @return [Hash]
167
168
  def default_api_params
168
- { :controlGroup => 'M', :dsState => 'A', :checksumType => 'DISABLED', :versionable => true}
169
+ return DS_DEFAULT_ATTRIBUTES.dup if new?
170
+ {}
169
171
  end
170
172
 
171
173
  # reset all profile attributes
@@ -22,12 +22,14 @@ module Rubydora
22
22
  # mapping object parameters to profile elements
23
23
  OBJ_ATTRIBUTES = {:state => :objState, :ownerId => :objOwnerId, :label => :objLabel, :logMessage => nil, :lastModifiedDate => :objLastModDate }
24
24
 
25
+ OBJ_DEFAULT_ATTRIBUTES = { }
26
+
25
27
  define_attribute_methods OBJ_ATTRIBUTES.keys
26
28
 
27
29
  OBJ_ATTRIBUTES.each do |attribute, profile_name|
28
30
  class_eval <<-RUBY
29
31
  def #{attribute.to_s}
30
- @#{attribute.to_s} || profile['#{profile_name.to_s}']
32
+ @#{attribute} || profile['#{profile_name.to_s}'] || OBJ_DEFAULT_ATTRIBUTES[:#{attribute}]
31
33
  end
32
34
 
33
35
  def #{attribute.to_s}= val
@@ -200,8 +202,8 @@ module Rubydora
200
202
  # @return [Hash]
201
203
  def to_api_params
202
204
  h = default_api_params
203
- OBJ_ATTRIBUTES.each do |attribute, profile_name|
204
- h[attribute] = instance_variable_get("@#{attribute.to_s}") if instance_variable_defined?("@#{attribute.to_s}")
205
+ changes.keys.select { |x| OBJ_ATTRIBUTES.key? x.to_sym }.each do |attribute|
206
+ h[attribute.to_sym] = send(attribute) unless send(attribute).nil?
205
207
  end
206
208
 
207
209
  h
@@ -210,7 +212,7 @@ module Rubydora
210
212
  # default datastream parameters
211
213
  # @return [Hash]
212
214
  def default_api_params
213
- { }
215
+ OBJ_DEFAULT_ATTRIBUTES.dup
214
216
  end
215
217
 
216
218
  # reset all profile attributes
@@ -1,17 +1,19 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Rubydora::Datastream do
4
+ before do
5
+ @mock_repository = mock(Rubydora::Repository)
6
+ @mock_object = mock(Rubydora::DigitalObject)
7
+ @mock_object.stub(:repository => @mock_repository, :pid => 'pid')
8
+ end
9
+
4
10
  describe "create" do
5
11
  before(:each) do
6
- @mock_repository = mock(Rubydora::Repository)
7
- @mock_object = mock(Rubydora::DigitalObject)
8
- @mock_object.should_receive(:repository).any_number_of_times.and_return(@mock_repository)
9
- @mock_object.should_receive(:pid).any_number_of_times.and_return 'pid'
12
+ @mock_repository.stub(:datastream) { raise("") }
10
13
  @datastream = Rubydora::Datastream.new @mock_object, 'dsid'
11
14
  end
12
15
 
13
16
  it "should be new" do
14
- @mock_repository.should_receive(:datastream).and_raise("")
15
17
  @datastream.new?.should == true
16
18
  end
17
19
 
@@ -19,14 +21,21 @@ describe Rubydora::Datastream do
19
21
  @datastream.changed?.should == false
20
22
  end
21
23
 
24
+ it "should have default values" do
25
+ @datastream.controlGroup == "M"
26
+ @datastream.dsState.should == "A"
27
+ @datastream.checksumType.should == "DISABLED"
28
+ @datastream.versionable.should == true
29
+ @datastream.changed.should be_empty
30
+ end
31
+
32
+
22
33
  it "should call the appropriate api on save" do
23
- @mock_repository.should_receive(:datastream).and_raise("")
24
34
  @mock_repository.should_receive(:add_datastream).with(hash_including(:pid => 'pid', :dsid => 'dsid', :controlGroup => 'M', :dsState => 'A'))
25
35
  @datastream.save
26
36
  end
27
37
 
28
38
  it "should be able to override defaults" do
29
- @mock_repository.should_receive(:datastream).and_raise("")
30
39
  @mock_repository.should_receive(:add_datastream).with(hash_including(:controlGroup => 'E'))
31
40
  @datastream.controlGroup = 'E'
32
41
  @datastream.save
@@ -35,10 +44,6 @@ describe Rubydora::Datastream do
35
44
 
36
45
  describe "retrieve" do
37
46
  before(:each) do
38
- @mock_repository = mock(Rubydora::Repository)
39
- @mock_object = mock(Rubydora::DigitalObject)
40
- @mock_object.should_receive(:repository).any_number_of_times.and_return(@mock_repository)
41
- @mock_object.should_receive(:pid).any_number_of_times.and_return 'pid'
42
47
  @datastream = Rubydora::Datastream.new @mock_object, 'dsid'
43
48
  @mock_repository.should_receive(:datastream).any_number_of_times.and_return <<-XML
44
49
  <datastreamProfile>
@@ -79,10 +84,6 @@ describe Rubydora::Datastream do
79
84
  describe "update" do
80
85
 
81
86
  before(:each) do
82
- @mock_repository = mock(Rubydora::Repository)
83
- @mock_object = mock(Rubydora::DigitalObject)
84
- @mock_object.should_receive(:repository).any_number_of_times.and_return(@mock_repository)
85
- @mock_object.should_receive(:pid).any_number_of_times.and_return 'pid'
86
87
  @datastream = Rubydora::Datastream.new @mock_object, 'dsid'
87
88
  @mock_repository.should_receive(:datastream).any_number_of_times.and_return <<-XML
88
89
  <datastreamProfile>
@@ -119,10 +120,8 @@ describe Rubydora::Datastream do
119
120
 
120
121
  describe "to_api_params" do
121
122
  before(:each) do
122
- @mock_object = mock(Rubydora::DigitalObject)
123
- @mock_object.should_receive(:repository).any_number_of_times.and_return(@mock_repository)
124
- @mock_object.should_receive(:pid).any_number_of_times.and_return 'pid'
125
123
  @datastream = Rubydora::Datastream.new @mock_object, 'dsid'
124
+ @datastream.stub(:profile) { {} }
126
125
  end
127
126
  it "should compile parameters to hash" do
128
127
  @datastream.send(:to_api_params).should == {:checksumType=>"DISABLED", :versionable=>true,
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubydora
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
5
- prerelease:
4
+ prerelease: false
6
5
  segments:
7
6
  - 0
8
7
  - 2
9
- - 1
10
- version: 0.2.1
8
+ - 2
9
+ segments_generated: true
10
+ version: 0.2.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Chris Beer
@@ -15,177 +15,177 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-10-29 00:00:00 -05:00
18
+ date: 2011-10-29 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  name: fastercsv
23
- type: :runtime
24
- prerelease: false
25
- version_requirements: &id001 !ruby/object:Gem::Requirement
23
+ requirement: &id001 !ruby/object:Gem::Requirement
26
24
  none: false
27
25
  requirements:
28
26
  - - ">="
29
27
  - !ruby/object:Gem::Version
30
- hash: 3
31
28
  segments:
32
29
  - 0
30
+ segments_generated: true
33
31
  version: "0"
34
- requirement: *id001
35
- - !ruby/object:Gem::Dependency
36
- name: rest-client
37
32
  type: :runtime
38
33
  prerelease: false
39
- version_requirements: &id002 !ruby/object:Gem::Requirement
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: rest-client
37
+ requirement: &id002 !ruby/object:Gem::Requirement
40
38
  none: false
41
39
  requirements:
42
40
  - - ">="
43
41
  - !ruby/object:Gem::Version
44
- hash: 3
45
42
  segments:
46
43
  - 0
44
+ segments_generated: true
47
45
  version: "0"
48
- requirement: *id002
49
- - !ruby/object:Gem::Dependency
50
- name: nokogiri
51
46
  type: :runtime
52
47
  prerelease: false
53
- version_requirements: &id003 !ruby/object:Gem::Requirement
48
+ version_requirements: *id002
49
+ - !ruby/object:Gem::Dependency
50
+ name: nokogiri
51
+ requirement: &id003 !ruby/object:Gem::Requirement
54
52
  none: false
55
53
  requirements:
56
54
  - - ">="
57
55
  - !ruby/object:Gem::Version
58
- hash: 3
59
56
  segments:
60
57
  - 0
58
+ segments_generated: true
61
59
  version: "0"
62
- requirement: *id003
63
- - !ruby/object:Gem::Dependency
64
- name: mime-types
65
60
  type: :runtime
66
61
  prerelease: false
67
- version_requirements: &id004 !ruby/object:Gem::Requirement
62
+ version_requirements: *id003
63
+ - !ruby/object:Gem::Dependency
64
+ name: mime-types
65
+ requirement: &id004 !ruby/object:Gem::Requirement
68
66
  none: false
69
67
  requirements:
70
68
  - - ">="
71
69
  - !ruby/object:Gem::Version
72
- hash: 3
73
70
  segments:
74
71
  - 0
72
+ segments_generated: true
75
73
  version: "0"
76
- requirement: *id004
77
- - !ruby/object:Gem::Dependency
78
- name: activesupport
79
74
  type: :runtime
80
75
  prerelease: false
81
- version_requirements: &id005 !ruby/object:Gem::Requirement
76
+ version_requirements: *id004
77
+ - !ruby/object:Gem::Dependency
78
+ name: activesupport
79
+ requirement: &id005 !ruby/object:Gem::Requirement
82
80
  none: false
83
81
  requirements:
84
82
  - - ">="
85
83
  - !ruby/object:Gem::Version
86
- hash: 3
87
84
  segments:
88
85
  - 0
86
+ segments_generated: true
89
87
  version: "0"
90
- requirement: *id005
91
- - !ruby/object:Gem::Dependency
92
- name: activemodel
93
88
  type: :runtime
94
89
  prerelease: false
95
- version_requirements: &id006 !ruby/object:Gem::Requirement
90
+ version_requirements: *id005
91
+ - !ruby/object:Gem::Dependency
92
+ name: activemodel
93
+ requirement: &id006 !ruby/object:Gem::Requirement
96
94
  none: false
97
95
  requirements:
98
96
  - - ">="
99
97
  - !ruby/object:Gem::Version
100
- hash: 3
101
98
  segments:
102
99
  - 0
100
+ segments_generated: true
103
101
  version: "0"
104
- requirement: *id006
105
- - !ruby/object:Gem::Dependency
106
- name: savon
107
102
  type: :runtime
108
103
  prerelease: false
109
- version_requirements: &id007 !ruby/object:Gem::Requirement
104
+ version_requirements: *id006
105
+ - !ruby/object:Gem::Dependency
106
+ name: savon
107
+ requirement: &id007 !ruby/object:Gem::Requirement
110
108
  none: false
111
109
  requirements:
112
110
  - - ">="
113
111
  - !ruby/object:Gem::Version
114
- hash: 3
115
112
  segments:
116
113
  - 0
114
+ segments_generated: true
117
115
  version: "0"
118
- requirement: *id007
116
+ type: :runtime
117
+ prerelease: false
118
+ version_requirements: *id007
119
119
  - !ruby/object:Gem::Dependency
120
120
  name: rake
121
- type: :development
122
- prerelease: false
123
- version_requirements: &id008 !ruby/object:Gem::Requirement
121
+ requirement: &id008 !ruby/object:Gem::Requirement
124
122
  none: false
125
123
  requirements:
126
124
  - - ">="
127
125
  - !ruby/object:Gem::Version
128
- hash: 3
129
126
  segments:
130
127
  - 0
128
+ segments_generated: true
131
129
  version: "0"
132
- requirement: *id008
133
- - !ruby/object:Gem::Dependency
134
- name: shoulda
135
130
  type: :development
136
131
  prerelease: false
137
- version_requirements: &id009 !ruby/object:Gem::Requirement
132
+ version_requirements: *id008
133
+ - !ruby/object:Gem::Dependency
134
+ name: shoulda
135
+ requirement: &id009 !ruby/object:Gem::Requirement
138
136
  none: false
139
137
  requirements:
140
138
  - - ">="
141
139
  - !ruby/object:Gem::Version
142
- hash: 3
143
140
  segments:
144
141
  - 0
142
+ segments_generated: true
145
143
  version: "0"
146
- requirement: *id009
147
- - !ruby/object:Gem::Dependency
148
- name: bundler
149
144
  type: :development
150
145
  prerelease: false
151
- version_requirements: &id010 !ruby/object:Gem::Requirement
146
+ version_requirements: *id009
147
+ - !ruby/object:Gem::Dependency
148
+ name: bundler
149
+ requirement: &id010 !ruby/object:Gem::Requirement
152
150
  none: false
153
151
  requirements:
154
152
  - - ">="
155
153
  - !ruby/object:Gem::Version
156
- hash: 3
157
154
  segments:
158
155
  - 0
156
+ segments_generated: true
159
157
  version: "0"
160
- requirement: *id010
161
- - !ruby/object:Gem::Dependency
162
- name: rspec
163
158
  type: :development
164
159
  prerelease: false
165
- version_requirements: &id011 !ruby/object:Gem::Requirement
160
+ version_requirements: *id010
161
+ - !ruby/object:Gem::Dependency
162
+ name: rspec
163
+ requirement: &id011 !ruby/object:Gem::Requirement
166
164
  none: false
167
165
  requirements:
168
166
  - - ">="
169
167
  - !ruby/object:Gem::Version
170
- hash: 3
171
168
  segments:
172
169
  - 0
170
+ segments_generated: true
173
171
  version: "0"
174
- requirement: *id011
175
- - !ruby/object:Gem::Dependency
176
- name: yard
177
172
  type: :development
178
173
  prerelease: false
179
- version_requirements: &id012 !ruby/object:Gem::Requirement
174
+ version_requirements: *id011
175
+ - !ruby/object:Gem::Dependency
176
+ name: yard
177
+ requirement: &id012 !ruby/object:Gem::Requirement
180
178
  none: false
181
179
  requirements:
182
180
  - - ">="
183
181
  - !ruby/object:Gem::Version
184
- hash: 3
185
182
  segments:
186
183
  - 0
184
+ segments_generated: true
187
185
  version: "0"
188
- requirement: *id012
186
+ type: :development
187
+ prerelease: false
188
+ version_requirements: *id012
189
189
  description: "Fedora Commons REST API ruby library : REQUIRES FCREPO 3.4+"
190
190
  email:
191
191
  - chris@cbeer.info
@@ -245,23 +245,25 @@ required_ruby_version: !ruby/object:Gem::Requirement
245
245
  requirements:
246
246
  - - ">="
247
247
  - !ruby/object:Gem::Version
248
- hash: 3
248
+ hash: -3650604307215364376
249
249
  segments:
250
250
  - 0
251
+ segments_generated: true
251
252
  version: "0"
252
253
  required_rubygems_version: !ruby/object:Gem::Requirement
253
254
  none: false
254
255
  requirements:
255
256
  - - ">="
256
257
  - !ruby/object:Gem::Version
257
- hash: 3
258
+ hash: -3650604307215364376
258
259
  segments:
259
260
  - 0
261
+ segments_generated: true
260
262
  version: "0"
261
263
  requirements: []
262
264
 
263
265
  rubyforge_project:
264
- rubygems_version: 1.6.2
266
+ rubygems_version: 1.3.7
265
267
  signing_key:
266
268
  specification_version: 3
267
269
  summary: Fedora Commons REST API ruby library