rof 1.2.6 → 1.2.7
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.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 827e88ec60564b1d9f6dbf9c268db50994dc0c1c
|
4
|
+
data.tar.gz: 4bf1f3095bdf70cc8b2f0968eb3041b56be0ce2e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9495282350fb90ae4b7a6a039ff8412e3092b59c12ac069b0ca3cfb14383146327ceb2d9768cd9ecfb4e1853e0336afc4ac2b553c7ad26d19862c310a171d286
|
7
|
+
data.tar.gz: c8413636f1e6178d046f857d30d005c27781ec177880702b4074f0fa10f9815089b0e76920dc0be097e22007eed2a92f5ac7a4ba655cbaa3dcba951fabe9e46b
|
@@ -71,19 +71,37 @@ module ROF
|
|
71
71
|
rof
|
72
72
|
end
|
73
73
|
|
74
|
-
class
|
74
|
+
class TooManyElementsError < RuntimeError
|
75
|
+
def initialize(context, expected_count, got_count)
|
76
|
+
super(%(Expected #{expected_count} in "#{context}" but instead got #{got_count}))
|
77
|
+
end
|
75
78
|
end
|
76
79
|
|
77
80
|
def force_cardinality_for_backwards_compatability(rof)
|
81
|
+
rof = force_rights_cardinality(rof)
|
82
|
+
rof = force_bendo_cardinality(rof)
|
83
|
+
rof
|
84
|
+
end
|
85
|
+
|
86
|
+
def force_rights_cardinality(rof)
|
78
87
|
rights = rof.fetch('rights', {})
|
79
88
|
if rights.key?('embargo-date')
|
80
89
|
embargo_dates = Array.wrap(rights['embargo-date'])
|
81
|
-
raise
|
90
|
+
raise TooManyElementsError.new('rights > embargo-date', 1, embargo_dates.size) if embargo_dates.size > 1
|
82
91
|
rof['rights']['embargo-date'] = embargo_dates.first
|
83
92
|
end
|
84
93
|
rof
|
85
94
|
end
|
86
95
|
|
96
|
+
def force_bendo_cardinality(rof)
|
97
|
+
if rof.key?('bendo-item')
|
98
|
+
bendo_items = Array.wrap(rof['bendo-item'])
|
99
|
+
raise TooManyElementsError.new('bendo-item', 1, bendo_items.size) if bendo_items.size > 1
|
100
|
+
rof['bendo-item'] = bendo_items.first
|
101
|
+
end
|
102
|
+
rof
|
103
|
+
end
|
104
|
+
|
87
105
|
public
|
88
106
|
|
89
107
|
# @api public
|
data/lib/rof/version.rb
CHANGED
@@ -117,35 +117,65 @@ module ROF
|
|
117
117
|
end
|
118
118
|
|
119
119
|
describe '#to_rof' do
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
"
|
124
|
-
|
125
|
-
|
126
|
-
|
120
|
+
describe 'for embargo-date' do
|
121
|
+
let(:initial_rof) do
|
122
|
+
{
|
123
|
+
"rights"=> {
|
124
|
+
"edit"=>["curate_batch_user"],
|
125
|
+
"embargo-date"=>["2016-11-16"],
|
126
|
+
"read"=>["wma1"],
|
127
|
+
"read-groups"=>["public"]
|
128
|
+
}
|
127
129
|
}
|
128
|
-
}
|
129
|
-
end
|
130
|
-
context 'with one embargo-date' do
|
131
|
-
it 'will have a single embargo date' do
|
132
|
-
rof = initial_rof
|
133
|
-
rof['rights']['embargo-date'] = ['2016-1-2']
|
134
|
-
expect(described_class.new(rof).to_rof['rights'].fetch('embargo-date')).to eq('2016-1-2')
|
135
130
|
end
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
131
|
+
context 'with one embargo-date' do
|
132
|
+
it 'will have a single embargo date' do
|
133
|
+
rof = initial_rof
|
134
|
+
rof['rights']['embargo-date'] = ['2016-1-2']
|
135
|
+
expect(described_class.new(rof).to_rof['rights'].fetch('embargo-date')).to eq('2016-1-2')
|
136
|
+
end
|
137
|
+
end
|
138
|
+
context 'with more than one embargo-date' do
|
139
|
+
it 'will raise an exception' do
|
140
|
+
rof = initial_rof
|
141
|
+
rof['rights']['embargo-date'] = ['2016-1-2', '2016-2-3']
|
142
|
+
expect { described_class.new(rof).to_rof }.to raise_error(described_class::TooManyElementsError)
|
143
|
+
end
|
144
|
+
end
|
145
|
+
context 'no embargo-date' do
|
146
|
+
it 'will not have an embargo-date' do
|
147
|
+
rof = initial_rof
|
148
|
+
rof['rights'].delete('embargo-date')
|
149
|
+
expect { described_class.new(rof).to_rof['rights'].fetch('embargo-date') }.to raise_error(KeyError)
|
150
|
+
end
|
142
151
|
end
|
143
152
|
end
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
153
|
+
describe 'bendo-item' do
|
154
|
+
let(:initial_rof) do
|
155
|
+
{
|
156
|
+
"bendo-item"=> ['abcd1']
|
157
|
+
}
|
158
|
+
end
|
159
|
+
context 'with one embargo-date' do
|
160
|
+
it 'will have a single embargo date' do
|
161
|
+
rof = initial_rof
|
162
|
+
rof['bendo-item'] = ['abcd1']
|
163
|
+
expect(described_class.new(rof).to_rof.fetch('bendo-item')).to eq('abcd1')
|
164
|
+
end
|
165
|
+
end
|
166
|
+
context 'with more than one embargo-date' do
|
167
|
+
it 'will raise an exception' do
|
168
|
+
rof = initial_rof
|
169
|
+
rof['bendo-item'] = ['abcd1', 'efgh1']
|
170
|
+
expect { described_class.new(rof).to_rof }.to raise_error(described_class::TooManyElementsError)
|
171
|
+
end
|
172
|
+
end
|
173
|
+
context 'no embargo-date' do
|
174
|
+
it 'will not have an embargo-date' do
|
175
|
+
rof = initial_rof
|
176
|
+
rof.delete('bendo-item')
|
177
|
+
expect { described_class.new(rof).to_rof.fetch('bendo-item') }.to raise_error(KeyError)
|
178
|
+
end
|
149
179
|
end
|
150
180
|
end
|
151
181
|
end
|