active-fedora 9.0.1 → 9.0.2
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 +4 -4
- data/lib/active_fedora/associations/builder/contains.rb +5 -1
- data/lib/active_fedora/fedora.rb +15 -1
- data/lib/active_fedora/file.rb +25 -6
- data/lib/active_fedora/loadable_from_json.rb +5 -1
- data/lib/active_fedora/persistence.rb +7 -3
- data/lib/active_fedora/version.rb +1 -1
- data/spec/integration/attached_files_spec.rb +24 -0
- data/spec/unit/active_fedora_spec.rb +4 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d965581bccc2e324f6336a4f7c5efb78efad4fcc
|
4
|
+
data.tar.gz: 72afbee2a1034a97575d0bfbfb74fed1e3d1ca14
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e72f35a6d6effd301066113a82479a9924e67b6f137e97db989cef3e9d7ac48790835d074fb617f222a07d7b9641ca49aac0bba4ec6e778da23340eff3edf857
|
7
|
+
data.tar.gz: 0689886286c8acc0aea9f4a19b70fac85b7da7d011ecdfcf13c140ab5e5479f900063d5ca5d88e94a315a83d88d72ccdd26b268240a6615596a481542f16c89b
|
@@ -19,7 +19,11 @@ module ActiveFedora::Associations::Builder
|
|
19
19
|
mixin.send(:define_method, name) do |*params|
|
20
20
|
association(name).reader(*params).tap do |file|
|
21
21
|
set_uri = uri.kind_of?(RDF::URI) ? uri.value.present? : uri.present?
|
22
|
-
|
22
|
+
if set_uri
|
23
|
+
file_uri = "#{uri}/#{name}"
|
24
|
+
file.uri = file_uri
|
25
|
+
file.exists! if contains_assertions.include?(file_uri)
|
26
|
+
end
|
23
27
|
end
|
24
28
|
end
|
25
29
|
end
|
data/lib/active_fedora/fedora.rb
CHANGED
@@ -13,8 +13,16 @@ module ActiveFedora
|
|
13
13
|
@config[:base_path] || '/'
|
14
14
|
end
|
15
15
|
|
16
|
+
def user
|
17
|
+
@config[:user]
|
18
|
+
end
|
19
|
+
|
20
|
+
def password
|
21
|
+
@config[:password]
|
22
|
+
end
|
23
|
+
|
16
24
|
def connection
|
17
|
-
@connection ||= CachingConnection.new(
|
25
|
+
@connection ||= CachingConnection.new(authorized_connection)
|
18
26
|
end
|
19
27
|
|
20
28
|
def ldp_resource_service
|
@@ -41,5 +49,11 @@ module ActiveFedora
|
|
41
49
|
@root_resource_path ||= base_path.sub(SLASH, BLANK)
|
42
50
|
end
|
43
51
|
|
52
|
+
def authorized_connection
|
53
|
+
connection = Faraday.new(host)
|
54
|
+
connection.basic_auth(user, password)
|
55
|
+
connection
|
56
|
+
end
|
57
|
+
|
44
58
|
end
|
45
59
|
end
|
data/lib/active_fedora/file.rb
CHANGED
@@ -58,14 +58,21 @@ module ActiveFedora
|
|
58
58
|
ldp_source.subject
|
59
59
|
end
|
60
60
|
|
61
|
+
# If this file have a parent with ldp#contains, we know it is not new.
|
62
|
+
# By tracking exists we prevent an unnecessary HEAD request.
|
61
63
|
def new_record?
|
62
|
-
ldp_source.new?
|
64
|
+
!@exists && ldp_source.new?
|
63
65
|
end
|
64
66
|
|
65
67
|
def uri= uri
|
66
68
|
@ldp_source = Ldp::Resource::BinarySource.new(ldp_connection, uri, '', ActiveFedora.fedora.host + ActiveFedora.fedora.base_path)
|
67
69
|
end
|
68
70
|
|
71
|
+
# If we know the record to exist (parent has LDP:contains), we can avoid unnecessary HEAD requests
|
72
|
+
def exists!
|
73
|
+
@exists = true
|
74
|
+
end
|
75
|
+
|
69
76
|
# When restoring from previous versions, we need to reload certain attributes from Fedora
|
70
77
|
def reload
|
71
78
|
return if new_record?
|
@@ -248,11 +255,11 @@ module ActiveFedora
|
|
248
255
|
ldp_source.content = content
|
249
256
|
if new_record?
|
250
257
|
ldp_source.create do |req|
|
251
|
-
req.headers
|
258
|
+
req.headers.merge!(headers)
|
252
259
|
end
|
253
260
|
else
|
254
261
|
ldp_source.update do |req|
|
255
|
-
req.headers
|
262
|
+
req.headers.merge!(headers)
|
256
263
|
end
|
257
264
|
end
|
258
265
|
reset
|
@@ -293,9 +300,21 @@ module ActiveFedora
|
|
293
300
|
# @returns [Stream] an object that responds to each
|
294
301
|
def stream(range = nil)
|
295
302
|
uri = URI.parse(self.uri)
|
296
|
-
headers
|
297
|
-
|
298
|
-
|
303
|
+
FileBody.new(uri, headers(range, authorization_key))
|
304
|
+
end
|
305
|
+
|
306
|
+
# @returns current authorization token from Ldp::Client
|
307
|
+
def authorization_key
|
308
|
+
self.ldp_source.client.http.headers.fetch("Authorization", nil)
|
309
|
+
end
|
310
|
+
|
311
|
+
# @param range [String] from #stream
|
312
|
+
# @param key [String] from #authorization_key
|
313
|
+
# @returns [Hash]
|
314
|
+
def headers(range, key, result = Hash.new)
|
315
|
+
result["Range"] = range if range
|
316
|
+
result["Authorization"] = key if key
|
317
|
+
result
|
299
318
|
end
|
300
319
|
|
301
320
|
class FileBody
|
@@ -62,6 +62,10 @@ module ActiveFedora
|
|
62
62
|
@values.map {|v| FakeStatement.new(v) }
|
63
63
|
end
|
64
64
|
|
65
|
+
def objects
|
66
|
+
@values
|
67
|
+
end
|
68
|
+
|
65
69
|
class FakeStatement
|
66
70
|
def initialize(value)
|
67
71
|
@value = value
|
@@ -89,7 +93,7 @@ module ActiveFedora
|
|
89
93
|
end
|
90
94
|
|
91
95
|
def reflection(predicate)
|
92
|
-
@model.outgoing_reflections.find { |key, reflection| reflection.predicate == predicate }.first
|
96
|
+
Array(@model.outgoing_reflections.find { |key, reflection| reflection.predicate == predicate }).first
|
93
97
|
end
|
94
98
|
end
|
95
99
|
|
@@ -39,9 +39,10 @@ module ActiveFedora
|
|
39
39
|
|
40
40
|
alias update_attributes update
|
41
41
|
|
42
|
-
#Deletes
|
43
|
-
#
|
44
|
-
#
|
42
|
+
# Deletes an object from Fedora and deletes the indexed record from Solr.
|
43
|
+
# Delete does not run any callbacks, so consider using _destroy_ instead.
|
44
|
+
# @param [Hash] opts
|
45
|
+
# @option opts [Boolean] :eradicate if passed in, eradicate the tombstone from Fedora
|
45
46
|
def delete(opts = {})
|
46
47
|
return self if new_record?
|
47
48
|
|
@@ -68,6 +69,9 @@ module ActiveFedora
|
|
68
69
|
freeze
|
69
70
|
end
|
70
71
|
|
72
|
+
# Delete the object from Fedora and Solr. Run any before/after/around callbacks for destroy
|
73
|
+
# @param [Hash] opts
|
74
|
+
# @option opts [Boolean] :eradicate if passed in, eradicate the tombstone from Fedora
|
71
75
|
def destroy(*args)
|
72
76
|
raise ReadOnlyRecord if readonly?
|
73
77
|
delete(*args)
|
@@ -1,6 +1,30 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe ActiveFedora::AttachedFiles do
|
4
|
+
describe "#contains" do
|
5
|
+
before do
|
6
|
+
class FooHistory < ActiveFedora::Base
|
7
|
+
contains 'child'
|
8
|
+
end
|
9
|
+
end
|
10
|
+
after do
|
11
|
+
Object.send(:remove_const, :FooHistory)
|
12
|
+
end
|
13
|
+
|
14
|
+
context "when the object exists" do
|
15
|
+
let!(:o) { FooHistory.create }
|
16
|
+
before do
|
17
|
+
o.child.content = "HMMM"
|
18
|
+
o.save
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should not need to do a head on the children" do
|
22
|
+
f = FooHistory.find(o.id)
|
23
|
+
expect(f.ldp_source.client).not_to receive(:head)
|
24
|
+
f.child.content
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
4
28
|
describe "serializing datastreams" do
|
5
29
|
before do
|
6
30
|
class TestingMetadataSerializing < ActiveFedora::Base
|
@@ -19,16 +19,18 @@ describe ActiveFedora do
|
|
19
19
|
|
20
20
|
let(:good_url) { ActiveFedora.fedora_config.credentials[:url] }
|
21
21
|
let(:bad_url) { good_url.gsub('/rest', '/') }
|
22
|
+
let(:user) { ActiveFedora.fedora_config.credentials[:user] }
|
23
|
+
let(:password) { ActiveFedora.fedora_config.credentials[:password] }
|
22
24
|
|
23
25
|
it "should connect OK" do
|
24
26
|
expect(ActiveFedora::Base.logger).to_not receive(:warn)
|
25
|
-
ActiveFedora::Fedora.new(url: good_url, base_path: '/test')
|
27
|
+
ActiveFedora::Fedora.new(url: good_url, base_path: '/test', user: user, password: password)
|
26
28
|
end
|
27
29
|
|
28
30
|
it "should not connect and warn" do
|
29
31
|
expect(ActiveFedora::Base.logger).to receive(:warn)
|
30
32
|
expect {
|
31
|
-
ActiveFedora::Fedora.new(url: bad_url, base_path: '/test')
|
33
|
+
ActiveFedora::Fedora.new(url: bad_url, base_path: '/test', user: user, password: password)
|
32
34
|
}.to raise_error Ldp::HttpError
|
33
35
|
end
|
34
36
|
end
|
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.
|
4
|
+
version: 9.0.2
|
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-02-
|
13
|
+
date: 2015-02-24 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rsolr
|
@@ -560,7 +560,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
560
560
|
version: '0'
|
561
561
|
requirements: []
|
562
562
|
rubyforge_project:
|
563
|
-
rubygems_version: 2.
|
563
|
+
rubygems_version: 2.4.5
|
564
564
|
signing_key:
|
565
565
|
specification_version: 4
|
566
566
|
summary: A convenience libary for manipulating documents in the Fedora Repository.
|