rof 1.2.6 → 1.2.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2904ea17597fc64687691d34928f1996007acaef
4
- data.tar.gz: 5bab7145ebb3b4390fcb0b45b9848d4286664ccc
3
+ metadata.gz: 827e88ec60564b1d9f6dbf9c268db50994dc0c1c
4
+ data.tar.gz: 4bf1f3095bdf70cc8b2f0968eb3041b56be0ce2e
5
5
  SHA512:
6
- metadata.gz: eec647ac396d07d11c04b8dfa0f72bc199c7b5c9720623f843cdbf1f9c827f8d078015a952a684cf9d52a7ad6b9ef6de472a8ecfde1fc3bd062a25e48487cae3
7
- data.tar.gz: 3753abfbb4bdecbc70b89f8068f41e52c830a9affb8d72f4e7ed1ee5797bd2672ecaf6afa745ace2ab96da4ed476f333aa6cae1f77309e90fb5e40eb72d4fd93
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 TooManyEmbargoDatesError < RuntimeError
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 TooManyEmbargoDatesError if embargo_dates.size > 1
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
@@ -1,3 +1,3 @@
1
1
  module ROF
2
- VERSION="1.2.6"
2
+ VERSION="1.2.7"
3
3
  end
@@ -117,35 +117,65 @@ module ROF
117
117
  end
118
118
 
119
119
  describe '#to_rof' do
120
- let(:initial_rof) do
121
- {
122
- "rights"=> {
123
- "edit"=>["curate_batch_user"],
124
- "embargo-date"=>["2016-11-16"],
125
- "read"=>["wma1"],
126
- "read-groups"=>["public"]
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
- end
137
- context 'with more than one embargo-date' do
138
- it 'will raise an exception' do
139
- rof = initial_rof
140
- rof['rights']['embargo-date'] = ['2016-1-2', '2016-2-3']
141
- expect { described_class.new(rof).to_rof }.to raise_error(described_class::TooManyEmbargoDatesError)
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
- context 'no embargo-date' do
145
- it 'will not have an embargo-date' do
146
- rof = initial_rof
147
- rof['rights'].delete('embargo-date')
148
- expect { described_class.new(rof).to_rof['rights'].fetch('embargo-date') }.to raise_error(KeyError)
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rof
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.6
4
+ version: 1.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Friesen