active-fedora 9.0.3 → 9.0.4

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: 505a6045300f42aa08d9d68632b7847cddc7b9a7
4
- data.tar.gz: 05360af6100e21a5513b612292da24cf01cf9b16
3
+ metadata.gz: 8399fafb48e7230ac7b01d1902b7f5c08cbbd32c
4
+ data.tar.gz: a7bba75db0807336e62720997ccc30465b492356
5
5
  SHA512:
6
- metadata.gz: 399d4f0a75a882db61ccaece0343dcdfa509670cc0e8aa8e11aa830a87797825ac3f923e9c577ef83f70ec02bd1bc7b7f770f7d242807fb443641677c504e70b
7
- data.tar.gz: 7a9b1ae26cbed3732b28bd337304765790393f4af1b3b8b4ebf1c98ae8036b1a2d7a8a2ce0779dbe98b8bdd49c5373f4e4900eed005d46806fda0f37740c5e6f
6
+ metadata.gz: 25eaf5eacaacbe1c4889f3c2cc2381a06a38a7aced2c5dd06b9ea6d5497b512b24f923fca57b8b3b1a49ace425841463a71c8d2e036dd3db6e2d46006bb09810
7
+ data.tar.gz: 8e5a5556ad3acd780f352feb6043053a41b1ae9be13446d269676748d46ce0830a4beae2550621b14af1ee897145eb7a6151d3a98d0a81ee60e49337ecd60527
@@ -1,3 +1,8 @@
1
+ v9.0.4
2
+ 2015-03-10: Refactor the AF::Base initializer [Justin Coyne]
3
+
4
+ 2015-03-10: Added missing id setter [Justin Coyne]
5
+
1
6
  v9.0.3
2
7
  2015-03-04: Encapsulate solr_escape and make it private [Justin Coyne]
3
8
 
@@ -33,13 +33,14 @@ module ActiveFedora
33
33
  # Also, if +attrs+ does not contain +:id+ but does contain +:namespace+ it will pass the
34
34
  # +:namespace+ value to Fedora::Repository.nextid to generate the next id available within
35
35
  # the given namespace.
36
- def initialize(attributes_or_resource_or_url = nil, &block)
36
+ def initialize(attributes_or_id = nil, &block)
37
37
  init_internals
38
- attributes = initialize_resource_and_attributes(attributes_or_resource_or_url)
38
+ attributes = initialize_attributes(attributes_or_id)
39
+ @ldp_source = build_ldp_resource(attributes.delete(:id))
39
40
  raise IllegalOperation, "Attempting to recreate existing ldp_source: `#{ldp_source.subject}'" unless ldp_source.new?
40
41
  assert_content_model
41
42
  load_attached_files
42
- self.attributes = attributes if attributes
43
+ self.attributes = attributes
43
44
 
44
45
  yield self if block_given?
45
46
  run_callbacks :initialize
@@ -138,7 +139,7 @@ module ActiveFedora
138
139
  else
139
140
  id = "/#{id}" unless id.start_with? SLASH
140
141
  unless ActiveFedora.fedora.base_path == SLASH || id.start_with?("#{ActiveFedora.fedora.base_path}/")
141
- id = ActiveFedora.fedora.base_path + id
142
+ id = ActiveFedora.fedora.base_path + id
142
143
  end
143
144
  ActiveFedora.fedora.host + id
144
145
  end
@@ -193,33 +194,22 @@ module ActiveFedora
193
194
  end
194
195
  end
195
196
 
196
- def initialize_resource_and_attributes attributes_or_resource_or_url
197
- case attributes_or_resource_or_url
197
+ def initialize_attributes attributes_or_id
198
+ case attributes_or_id
198
199
  when String
199
- @ldp_source = build_ldp_resource(attributes_or_resource_or_url)
200
- @attributes = {}.with_indifferent_access
200
+ attributes = {id: attributes_or_id}.with_indifferent_access
201
201
  when Hash
202
- attributes = attributes_or_resource_or_url
203
-
204
- id = attributes.delete(:id)
205
-
202
+ attributes = attributes_or_id.with_indifferent_access
206
203
  # TODO: Remove when we decide using 'pid' is no longer supported.
207
- if !id && attributes.has_key?(:pid)
204
+ if !attributes.key?(:id) && attributes.key?(:pid)
208
205
  Deprecation.warn Core, 'Initializing with :pid is deprecated and will be removed in active-fedora 10.0. Use :id instead'
209
- id = attributes.delete(:pid)
206
+ attributes[:id] = attributes.delete(:pid)
210
207
  end
211
208
 
212
- attributes = attributes.with_indifferent_access if attributes
213
- @ldp_source = if id
214
- build_ldp_resource(id)
215
- else
216
- build_ldp_resource
217
- end
218
209
  when NilClass
219
- @ldp_source = build_ldp_resource
220
210
  attributes = {}.with_indifferent_access
221
211
  else
222
- raise ArgumentError, "#{attributes_or_resource_or_url.class} is not acceptable"
212
+ raise ArgumentError, "#{attributes_or_id.class} is not acceptable"
223
213
  end
224
214
  return attributes
225
215
  end
@@ -34,6 +34,12 @@ module ActiveFedora
34
34
  end
35
35
  end
36
36
 
37
+ def id=(id)
38
+ raise "ID has already been set to #{self.id}" if self.id
39
+ @ldp_source = build_ldp_resource(id.to_s)
40
+ end
41
+
42
+
37
43
  # TODO: Remove after we no longer support #pid.
38
44
  def pid
39
45
  Deprecation.warn FedoraAttributes, "#{self.class}#pid is deprecated and will be removed in active-fedora 10.0. Use #{self.class}#id instead."
@@ -1,3 +1,3 @@
1
1
  module ActiveFedora
2
- VERSION = "9.0.3"
2
+ VERSION = "9.0.4"
3
3
  end
@@ -4,6 +4,30 @@ require 'spec_helper'
4
4
  describe ActiveFedora::Base do
5
5
  it_behaves_like "An ActiveModel"
6
6
 
7
+ describe "id=" do
8
+ before do
9
+ class FooHistory < ActiveFedora::Base
10
+ property :title, predicate: ::RDF::DC.title
11
+ end
12
+ end
13
+ after do
14
+ Object.send(:remove_const, :FooHistory)
15
+ end
16
+
17
+ subject { FooHistory.new(title: ["A good title"]) }
18
+ before { subject.id = 9 }
19
+
20
+ it "is settable" do
21
+ expect(subject.id).to eq '9'
22
+ expect(subject.title).to eq ["A good title"]
23
+ end
24
+
25
+ it "is only settable once" do
26
+ expect { subject.id = 10 }.to raise_error "ID has already been set to 9"
27
+ expect(subject.id).to eq '9'
28
+ end
29
+ end
30
+
7
31
  describe 'descendants' do
8
32
  it "should record the decendants" do
9
33
  expect(ActiveFedora::Base.descendants).to include(ModsArticle, SpecialThing)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active-fedora
3
3
  version: !ruby/object:Gem::Version
4
- version: 9.0.3
4
+ version: 9.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Zumwalt
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2015-03-06 00:00:00.000000000 Z
13
+ date: 2015-03-11 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rsolr
@@ -565,3 +565,4 @@ signing_key:
565
565
  specification_version: 4
566
566
  summary: A convenience libary for manipulating documents in the Fedora Repository.
567
567
  test_files: []
568
+ has_rdoc: