active-fedora 9.0.2 → 9.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/History.txt +85 -0
- data/README.md +2 -4
- data/active-fedora.gemspec +1 -0
- data/lib/active_fedora.rb +5 -0
- data/lib/active_fedora/associations/builder/has_many.rb +1 -1
- data/lib/active_fedora/associations/collection_association.rb +1 -18
- data/lib/active_fedora/associations/contains_association.rb +3 -1
- data/lib/active_fedora/associations/has_and_belongs_to_many_association.rb +12 -10
- data/lib/active_fedora/attached_files.rb +6 -3
- data/lib/active_fedora/change_set.rb +2 -2
- data/lib/active_fedora/core.rb +26 -38
- data/lib/active_fedora/core/fedora_id_translator.rb +12 -0
- data/lib/active_fedora/core/fedora_uri_translator.rb +9 -0
- data/lib/active_fedora/errors.rb +4 -0
- data/lib/active_fedora/fedora_attributes.rb +25 -1
- data/lib/active_fedora/file.rb +2 -15
- data/lib/active_fedora/inheritable_accessors.rb +26 -0
- data/lib/active_fedora/nom_datastream.rb +6 -4
- data/lib/active_fedora/rdf/ntriples_rdf_datastream.rb +0 -4
- data/lib/active_fedora/reflection.rb +3 -1
- data/lib/active_fedora/relation/finder_methods.rb +36 -5
- data/lib/active_fedora/version.rb +1 -1
- data/lib/active_fedora/versions_graph.rb +7 -8
- data/spec/integration/associations_spec.rb +64 -21
- data/spec/integration/belongs_to_association_spec.rb +118 -47
- data/spec/integration/collection_association_spec.rb +46 -0
- data/spec/integration/has_and_belongs_to_many_associations_spec.rb +178 -139
- data/spec/integration/query_result_builder_spec.rb +2 -2
- data/spec/integration/versionable_spec.rb +38 -1
- data/spec/samples/samples.rb +0 -1
- data/spec/spec_helper.rb +1 -0
- data/spec/unit/base_spec.rb +98 -0
- data/spec/unit/change_set_spec.rb +4 -2
- data/spec/unit/core/fedora_id_translator_spec.rb +20 -0
- data/spec/unit/core/fedora_uri_translator_spec.rb +19 -0
- data/spec/unit/core_spec.rb +50 -0
- data/spec/unit/has_many_association_spec.rb +27 -2
- data/spec/unit/qualified_dublin_core_datastream_spec.rb +0 -6
- data/spec/unit/reflection_spec.rb +44 -0
- data/spec/unit/simple_datastream_spec.rb +32 -0
- metadata +23 -13
- data/spec/samples/marpa-dc_datastream.rb +0 -102
- data/spec/samples/models/audio_record.rb +0 -29
- data/spec/samples/models/image.rb +0 -5
- data/spec/samples/models/oral_history.rb +0 -36
- data/spec/samples/models/seminar.rb +0 -29
- data/spec/samples/models/seminar_audio_file.rb +0 -32
- data/spec/samples/oral_history_sample_model.rb +0 -30
- data/spec/samples/special_thing.rb +0 -44
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ebf611de1fa3721bc0d53f15e6210ced8509072da4f1406f818e2f14c5f11be2
|
4
|
+
data.tar.gz: 1f6729e4bce4f1b03ba5ba2864c4dbe84ae454932221de98fe4357b8e80e69e4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f5ba1bc7bcb326f435f1ed88cad1e1a7b68c04b122472379430bf320a634e67e3da72c13c424dda5ba1f9d2673aec820a74d9b7adffb60bd9c23498f89ed7b52
|
7
|
+
data.tar.gz: 2e06a0593ec85862f1995277e7a530f05bff3f31e30ed80a4719c04beb8807c28060ec275fa2d833c118b83ad22fb812c5a07d848823bbfc9d90bb8693683fd9
|
data/History.txt
CHANGED
@@ -1,3 +1,88 @@
|
|
1
|
+
v9.0.8
|
2
|
+
|
3
|
+
2015-04-15: Revert "Move the indexing logic to the model. Fixes #736"
|
4
|
+
[Justin Coyne] (cabb9057)
|
5
|
+
|
6
|
+
2015-04-15: Fix deleting from a HABTM when the inverse_of is a
|
7
|
+
has_many. Fixes #763 [Justin Coyne] (b1e67fb1)
|
8
|
+
|
9
|
+
2015-04-15: Remove a spec that is a duplicate of
|
10
|
+
integration/collection_association_spec.rb:92 [Justin Coyne]
|
11
|
+
(bdafd50d)
|
12
|
+
|
13
|
+
2015-04-15: Leverage the code in AssociationRelation to find the
|
14
|
+
inverse. Fixes #760 [Justin Coyne] (c764ea70)
|
15
|
+
|
16
|
+
2015-04-15: Make #translate_id_to_uri/uri_to_id reliable. [Trey
|
17
|
+
Terrell] (80a4e3fd)
|
18
|
+
|
19
|
+
2015-04-15: Find best model match in case of inheritance [Stuart
|
20
|
+
Kenny] (481a9cd4)
|
21
|
+
|
22
|
+
2015-04-15: Requires 'deprecation' for ActiveFedora::File [Andrew
|
23
|
+
Myers] (14be5cf6)
|
24
|
+
|
25
|
+
2015-04-07: The indexing hints should be inheritable [Justin Coyne]
|
26
|
+
(c8d41b91)
|
27
|
+
|
28
|
+
v9.0.7
|
29
|
+
2015-04-06: Only set/save the inverse on a HABTM if the inverse is also HABTM
|
30
|
+
previously we were getting: [Justin Coyne]
|
31
|
+
|
32
|
+
2015-04-06: Derive a foreign_key ending with `_ids` if the inverse is a
|
33
|
+
collection [Justin Coyne]
|
34
|
+
|
35
|
+
2015-04-06: Find inverse relations when class_names have modules [Justin Coyne]
|
36
|
+
|
37
|
+
2015-04-06: Raise an error when the inverse relationship can not be found.
|
38
|
+
Previously a "SystemStackError: Stack too deep" was encountered in this
|
39
|
+
situation [Justin Coyne]
|
40
|
+
|
41
|
+
2015-04-02: Add a mechanism to set rdf_label on the ActiveTriple resource
|
42
|
+
[Justin Coyne]
|
43
|
+
|
44
|
+
2015-04-03: Refactor has_and_belongs_to_many_associations_spec [Justin Coyne]
|
45
|
+
|
46
|
+
2015-04-03: Remove unused sample classes [Justin Coyne]
|
47
|
+
|
48
|
+
2015-04-02: Sort versions as dates not as strings [Justin Coyne]
|
49
|
+
|
50
|
+
2015-04-01: Prevents an object from being loaded to the incorrect class. For
|
51
|
+
example, when loading a batch object it should be loaded into a Batch (and not a
|
52
|
+
File for example.) [Justin Coyne]
|
53
|
+
|
54
|
+
2015-03-27: Move the indexing logic to the model. Fixes #736 You should now add
|
55
|
+
indexing hints to has_attributes by passing a block similar to how you do it
|
56
|
+
with rdf properties. e.g.: [Justin Coyne]
|
57
|
+
|
58
|
+
v9.0.6
|
59
|
+
2015-03-26: Setting type should not wipe out properties. Fixes #737 [Justin Coyne]
|
60
|
+
|
61
|
+
v9.0.5
|
62
|
+
2015-03-25: Properties named *_id should not break the change set [Chris Colvard]
|
63
|
+
|
64
|
+
2015-03-24: Add rdf:type assertions to ActiveFedora::Base [Justin Coyne]
|
65
|
+
|
66
|
+
2015-03-24: Add documentation that differentiates attach_file from add_file [Justin Coyne]
|
67
|
+
|
68
|
+
2015-03-24: Remove #default_attributes. Fixes #732 [Chris Colvard]
|
69
|
+
|
70
|
+
2015-03-18: Make sure datastreams get configured on load as well as new/create [Michael B. Klein]
|
71
|
+
|
72
|
+
2015-03-17: Allow a has_many association to specify an explicit foreign key via the :as option [Michael B. Klein]
|
73
|
+
|
74
|
+
v9.0.4
|
75
|
+
2015-03-10: Refactor the AF::Base initializer [Justin Coyne]
|
76
|
+
|
77
|
+
2015-03-10: Added missing id setter [Justin Coyne]
|
78
|
+
|
79
|
+
v9.0.3
|
80
|
+
2015-03-04: Encapsulate solr_escape and make it private [Justin Coyne]
|
81
|
+
|
82
|
+
2015-03-04: Update readme [Justin Coyne]
|
83
|
+
|
84
|
+
2015-02-28: Use modified RSolr.solr_escape method [Adam Wead]
|
85
|
+
|
1
86
|
v9.0.0
|
2
87
|
2015-01-30: When save! is called only validate once [Justin Coyne]
|
3
88
|
|
data/README.md
CHANGED
@@ -6,12 +6,10 @@ Description
|
|
6
6
|
[![Dependencies](https://gemnasium.com/projecthydra/active_fedora.png)](https://gemnasium.com/projecthydra/active\_fedora)
|
7
7
|
[![Coverage Status](https://img.shields.io/coveralls/projecthydra/active_fedora.svg)](https://coveralls.io/r/projecthydra/active_fedora)
|
8
8
|
|
9
|
-
|
9
|
+
ActiveFedora is a Ruby gem for creating and
|
10
10
|
managing objects in the Fedora Repository Architecture
|
11
11
|
([http://fedora-commons.org](http://fedora-commons.org)). ActiveFedora
|
12
|
-
is loosely based on “ActiveRecord” in Rails.
|
13
|
-
ActiveFedora depends on Rails 3, specifically activemodel and
|
14
|
-
activesupport.
|
12
|
+
is loosely based on “ActiveRecord” in Rails. Version 9.0+ works with Fedora 4 and prior versions work on Fedora 3.
|
15
13
|
|
16
14
|
Getting Help
|
17
15
|
------------
|
data/active-fedora.gemspec
CHANGED
@@ -30,6 +30,7 @@ Gem::Specification.new do |s|
|
|
30
30
|
s.add_development_dependency "rake"
|
31
31
|
s.add_development_dependency "jettywrapper", ">= 2.0.0"
|
32
32
|
s.add_development_dependency "rspec", "~> 3.0"
|
33
|
+
s.add_development_dependency "rspec-its"
|
33
34
|
s.add_development_dependency "equivalent-xml"
|
34
35
|
s.add_development_dependency "simplecov", '~> 0.7.1'
|
35
36
|
|
data/lib/active_fedora.rb
CHANGED
@@ -51,6 +51,10 @@ module ActiveFedora #:nodoc:
|
|
51
51
|
autoload :ChangeSet
|
52
52
|
autoload :Config
|
53
53
|
autoload :Core
|
54
|
+
autoload_under 'core' do
|
55
|
+
autoload :FedoraIdTranslator
|
56
|
+
autoload :FedoraUriTranslator
|
57
|
+
end
|
54
58
|
autoload :Datastream
|
55
59
|
autoload :Datastreams
|
56
60
|
autoload :DelegatedAttribute
|
@@ -63,6 +67,7 @@ module ActiveFedora #:nodoc:
|
|
63
67
|
autoload :FixityService
|
64
68
|
autoload :Indexing
|
65
69
|
autoload :IndexingService
|
70
|
+
autoload :InheritableAccessors
|
66
71
|
autoload :LdpCache
|
67
72
|
autoload :LdpResource
|
68
73
|
autoload :LdpResourceService
|
@@ -343,29 +343,12 @@ module ActiveFedora
|
|
343
343
|
def find_reflection
|
344
344
|
return reflection if @reflection.options[:predicate]
|
345
345
|
if @reflection.class_name && @reflection.class_name != 'ActiveFedora::Base' && @reflection.macro != :has_and_belongs_to_many
|
346
|
-
|
347
|
-
begin
|
348
|
-
find_reflection_for_relation(@reflection.class_name.constantize)
|
349
|
-
rescue NameError
|
350
|
-
raise "No :predicate attribute was set or could be inferred for #{@reflection.macro} #{@reflection.name.inspect} on #{@owner.class}"
|
351
|
-
end
|
346
|
+
@reflection.inverse_of || raise("No :inverse_of or :predicate attribute was set or could be inferred for #{@reflection.macro} #{@reflection.name.inspect} on #{@owner.class}")
|
352
347
|
else
|
353
348
|
raise "Couldn't find reflection"
|
354
349
|
end
|
355
350
|
end
|
356
351
|
|
357
|
-
def find_reflection_for_relation(klass, inverse_relation=@owner.class.to_s.underscore.to_sym)
|
358
|
-
raise "Unable to lookup the :predicate attribute for #{@reflection.macro} #{@reflection.name.inspect} on #{@owner.class} because #{klass} specifies \"class_name: 'ActiveFedora::Base'\". Either specify a specific class_name in #{klass} or set :predicate in the #{@reflection.macro} declaration on #{@owner.class}" if inverse_relation == :'active_fedora/base'
|
359
|
-
if klass.reflections.key?(inverse_relation)
|
360
|
-
# Try it singular
|
361
|
-
return klass.reflections[inverse_relation]
|
362
|
-
elsif klass.reflections.key?(inverse_relation.to_s.pluralize.to_sym)
|
363
|
-
# Try it plural
|
364
|
-
return klass.reflections[inverse_relation.to_s.pluralize.to_sym]
|
365
|
-
end
|
366
|
-
find_reflection_for_relation(klass, @owner.class.superclass.to_s.underscore.to_sym)
|
367
|
-
end
|
368
|
-
|
369
352
|
def create_record(attributes, raise = false)
|
370
353
|
attributes.update(@reflection.options[:conditions]) if @reflection.options[:conditions].is_a?(Hash)
|
371
354
|
ensure_owner_is_not_new
|
@@ -18,13 +18,16 @@ module ActiveFedora
|
|
18
18
|
owner[reflection.foreign_key] ||= []
|
19
19
|
owner[reflection.foreign_key] += [record.id]
|
20
20
|
|
21
|
-
if
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
21
|
+
# Only if they've explicitly stated the inverse in the options
|
22
|
+
if reflection.options[:inverse_of]
|
23
|
+
inverse = reflection.inverse_of
|
24
|
+
if owner.new_record?
|
25
|
+
ActiveFedora::Base.logger.warn("has_and_belongs_to_many #{reflection.inspect} is cowardly refusing to insert the inverse relationship into #{record}, because #{owner} is not persisted yet.") if ActiveFedora::Base.logger
|
26
|
+
elsif inverse.has_and_belongs_to_many?
|
27
|
+
record[inverse.foreign_key] ||= []
|
28
|
+
record[inverse.foreign_key] += [owner.id]
|
29
|
+
record.save
|
30
|
+
end
|
28
31
|
end
|
29
32
|
|
30
33
|
return true
|
@@ -76,9 +79,8 @@ module ActiveFedora
|
|
76
79
|
records.each do |r|
|
77
80
|
owner[reflection.foreign_key] -= [r.id]
|
78
81
|
|
79
|
-
if
|
80
|
-
inverse
|
81
|
-
r[inverse.foreign_key] -= [owner.id]
|
82
|
+
if inverse = @reflection.inverse_of
|
83
|
+
r[inverse.foreign_key] -= [owner.id] if inverse.has_and_belongs_to_many?
|
82
84
|
r.association(inverse.name).reset
|
83
85
|
r.save
|
84
86
|
end
|
@@ -53,7 +53,10 @@ module ActiveFedora
|
|
53
53
|
end
|
54
54
|
end
|
55
55
|
|
56
|
-
#
|
56
|
+
# Add an ActiveFedora::File to the object.
|
57
|
+
# @param [ActiveFedora::File] file
|
58
|
+
# @param [String] file_path
|
59
|
+
# @param [Hash] opts
|
57
60
|
# @return [String] path of the added datastream
|
58
61
|
def attach_file(file, file_path, opts={})
|
59
62
|
create_singleton_association(file_path)
|
@@ -80,9 +83,9 @@ module ActiveFedora
|
|
80
83
|
add_file(file, opts)
|
81
84
|
end
|
82
85
|
|
83
|
-
# Attach the given
|
86
|
+
# Attach the given stream/string to object
|
84
87
|
#
|
85
|
-
# @param [
|
88
|
+
# @param [IO, String] file the file to add
|
86
89
|
# @param [Hash] opts options: :dsid, :prefix, :mime_type
|
87
90
|
# @option opts [String] :path The file path
|
88
91
|
# @option opts [String] :prefix The path prefix (for auto-generated path)
|
@@ -19,8 +19,8 @@ module ActiveFedora
|
|
19
19
|
|
20
20
|
def changes
|
21
21
|
@changes ||= changed_attributes.each_with_object({}) do |key, result|
|
22
|
-
if
|
23
|
-
predicate = object.association(
|
22
|
+
if object.respond_to?(:association) && object.association(key.to_sym).present?
|
23
|
+
predicate = object.association(key.to_sym).reflection.predicate
|
24
24
|
result[predicate] = graph.query(predicate: predicate)
|
25
25
|
elsif object.class.properties.keys.include?(key)
|
26
26
|
predicate = graph.reflections.reflect_on_property(key).predicate
|
data/lib/active_fedora/core.rb
CHANGED
@@ -14,14 +14,25 @@ module ActiveFedora
|
|
14
14
|
# :singleton-method
|
15
15
|
#
|
16
16
|
# Accepts a proc that takes an id and transforms it to a URI
|
17
|
-
|
17
|
+
mattr_reader :translate_id_to_uri do
|
18
|
+
FedoraIdTranslator
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.translate_id_to_uri=(translator)
|
22
|
+
@@translate_id_to_uri = translator || FedoraIdTranslator
|
23
|
+
end
|
18
24
|
|
19
25
|
##
|
20
26
|
# :singleton-method
|
21
27
|
#
|
22
28
|
# Accepts a proc that takes a uri and transforms it to an id
|
23
|
-
|
29
|
+
mattr_reader :translate_uri_to_id do
|
30
|
+
FedoraUriTranslator
|
31
|
+
end
|
24
32
|
|
33
|
+
def self.translate_uri_to_id=(translator)
|
34
|
+
@@translate_uri_to_id = translator || FedoraUriTranslator
|
35
|
+
end
|
25
36
|
end
|
26
37
|
|
27
38
|
def ldp_source
|
@@ -33,13 +44,14 @@ module ActiveFedora
|
|
33
44
|
# Also, if +attrs+ does not contain +:id+ but does contain +:namespace+ it will pass the
|
34
45
|
# +:namespace+ value to Fedora::Repository.nextid to generate the next id available within
|
35
46
|
# the given namespace.
|
36
|
-
def initialize(
|
47
|
+
def initialize(attributes_or_id = nil, &block)
|
37
48
|
init_internals
|
38
|
-
attributes =
|
49
|
+
attributes = initialize_attributes(attributes_or_id)
|
50
|
+
@ldp_source = build_ldp_resource(attributes.delete(:id))
|
39
51
|
raise IllegalOperation, "Attempting to recreate existing ldp_source: `#{ldp_source.subject}'" unless ldp_source.new?
|
40
52
|
assert_content_model
|
41
53
|
load_attached_files
|
42
|
-
self.attributes = attributes
|
54
|
+
self.attributes = attributes
|
43
55
|
|
44
56
|
yield self if block_given?
|
45
57
|
run_callbacks :initialize
|
@@ -133,27 +145,14 @@ module ActiveFedora
|
|
133
145
|
# Transforms an id into a uri
|
134
146
|
# if translate_id_to_uri is set it uses that proc, otherwise just the default
|
135
147
|
def id_to_uri(id)
|
136
|
-
|
137
|
-
translate_id_to_uri.call(id)
|
138
|
-
else
|
139
|
-
id = "/#{id}" unless id.start_with? SLASH
|
140
|
-
unless ActiveFedora.fedora.base_path == SLASH || id.start_with?("#{ActiveFedora.fedora.base_path}/")
|
141
|
-
id = ActiveFedora.fedora.base_path + id
|
142
|
-
end
|
143
|
-
ActiveFedora.fedora.host + id
|
144
|
-
end
|
148
|
+
translate_id_to_uri.call(id)
|
145
149
|
end
|
146
150
|
|
147
151
|
##
|
148
152
|
# Transforms a uri into an id
|
149
153
|
# if translate_uri_to_id is set it uses that proc, otherwise just the default
|
150
154
|
def uri_to_id(uri)
|
151
|
-
|
152
|
-
translate_uri_to_id.call(uri)
|
153
|
-
else
|
154
|
-
id = uri.to_s.sub(ActiveFedora.fedora.host + ActiveFedora.fedora.base_path, '')
|
155
|
-
id.start_with?('/') ? id[1..-1] : id
|
156
|
-
end
|
155
|
+
translate_uri_to_id.call(uri)
|
157
156
|
end
|
158
157
|
|
159
158
|
##
|
@@ -193,33 +192,22 @@ module ActiveFedora
|
|
193
192
|
end
|
194
193
|
end
|
195
194
|
|
196
|
-
def
|
197
|
-
case
|
195
|
+
def initialize_attributes attributes_or_id
|
196
|
+
case attributes_or_id
|
198
197
|
when String
|
199
|
-
|
200
|
-
@attributes = {}.with_indifferent_access
|
198
|
+
attributes = {id: attributes_or_id}.with_indifferent_access
|
201
199
|
when Hash
|
202
|
-
attributes =
|
203
|
-
|
204
|
-
id = attributes.delete(:id)
|
205
|
-
|
200
|
+
attributes = attributes_or_id.with_indifferent_access
|
206
201
|
# TODO: Remove when we decide using 'pid' is no longer supported.
|
207
|
-
if !id && attributes.
|
202
|
+
if !attributes.key?(:id) && attributes.key?(:pid)
|
208
203
|
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)
|
204
|
+
attributes[:id] = attributes.delete(:pid)
|
210
205
|
end
|
211
206
|
|
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
207
|
when NilClass
|
219
|
-
@ldp_source = build_ldp_resource
|
220
208
|
attributes = {}.with_indifferent_access
|
221
209
|
else
|
222
|
-
raise ArgumentError, "#{
|
210
|
+
raise ArgumentError, "#{attributes_or_id.class} is not acceptable"
|
223
211
|
end
|
224
212
|
return attributes
|
225
213
|
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module ActiveFedora::Core
|
2
|
+
class FedoraIdTranslator
|
3
|
+
SLASH = '/'.freeze
|
4
|
+
def self.call(id)
|
5
|
+
id = "/#{id}" unless id.start_with? SLASH
|
6
|
+
unless ActiveFedora.fedora.base_path == SLASH || id.start_with?("#{ActiveFedora.fedora.base_path}/")
|
7
|
+
id = ActiveFedora.fedora.base_path + id
|
8
|
+
end
|
9
|
+
ActiveFedora.fedora.host + id
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
data/lib/active_fedora/errors.rb
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
module ActiveFedora
|
2
2
|
module FedoraAttributes
|
3
3
|
extend ActiveSupport::Concern
|
4
|
+
include InheritableAccessors
|
4
5
|
|
5
6
|
included do
|
6
7
|
include ActiveTriples::Properties
|
7
8
|
include ActiveTriples::Reflection
|
8
|
-
delegate :rdf_subject, :get_values, to: :resource
|
9
|
+
delegate :rdf_subject, :get_values, :type, to: :resource
|
9
10
|
|
10
11
|
property :has_model, predicate: ActiveFedora::RDF::Fcrepo::Model.hasModel
|
11
12
|
property :create_date, predicate: ActiveFedora::RDF::Fcrepo4.created
|
@@ -18,6 +19,8 @@ module ActiveFedora
|
|
18
19
|
def modified_date
|
19
20
|
super.first
|
20
21
|
end
|
22
|
+
|
23
|
+
define_inheritable_accessor(:type, :rdf_label)
|
21
24
|
end
|
22
25
|
|
23
26
|
# Override ActiveTriples method for setting properties
|
@@ -34,6 +37,12 @@ module ActiveFedora
|
|
34
37
|
end
|
35
38
|
end
|
36
39
|
|
40
|
+
def id=(id)
|
41
|
+
raise "ID has already been set to #{self.id}" if self.id
|
42
|
+
@ldp_source = build_ldp_resource(id.to_s)
|
43
|
+
end
|
44
|
+
|
45
|
+
|
37
46
|
# TODO: Remove after we no longer support #pid.
|
38
47
|
def pid
|
39
48
|
Deprecation.warn FedoraAttributes, "#{self.class}#pid is deprecated and will be removed in active-fedora 10.0. Use #{self.class}#id instead."
|
@@ -56,12 +65,21 @@ module ActiveFedora
|
|
56
65
|
@resource ||= self.class.resource_class.new(@ldp_source.graph.rdf_subject, @ldp_source.graph)
|
57
66
|
end
|
58
67
|
|
68
|
+
# You can set the URI to use for the rdf_label on ClassMethods.rdf_label, then on
|
69
|
+
# the instance, calling rdf_label returns the value of that configured property
|
70
|
+
def rdf_label
|
71
|
+
resource.rdf_label
|
72
|
+
end
|
73
|
+
|
59
74
|
module ClassMethods
|
60
75
|
# We make a unique class, because properties belong to a class.
|
61
76
|
# This keeps properties from different objects separate.
|
77
|
+
# Since the copy of properties can only happen once, we don't want to invoke it
|
78
|
+
# until all properties have been defined.
|
62
79
|
def resource_class
|
63
80
|
@generated_resource_class ||= begin
|
64
81
|
klass = self.const_set(:GeneratedResourceSchema, Class.new(ActiveTriples::Resource))
|
82
|
+
klass.configure active_triple_options
|
65
83
|
klass.properties.merge(self.properties).each do |property, config|
|
66
84
|
klass.property(config.term,
|
67
85
|
predicate: config.predicate,
|
@@ -70,6 +88,12 @@ module ActiveFedora
|
|
70
88
|
klass
|
71
89
|
end
|
72
90
|
end
|
91
|
+
|
92
|
+
private
|
93
|
+
# @return a Hash of options suitable for passing to ActiveTriples::Base.configure
|
94
|
+
def active_triple_options
|
95
|
+
{ type: type, rdf_label: rdf_label }
|
96
|
+
end
|
73
97
|
end
|
74
98
|
end
|
75
99
|
end
|