active-fedora 7.0.0.rc2 → 7.0.0.rc3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +13 -3
- data/CONTRIBUTORS.md +1 -0
- data/Gemfile +2 -3
- data/active-fedora.gemspec +4 -3
- data/gemfiles/rails3.gemfile +1 -7
- data/gemfiles/rails4.1.gemfile +5 -0
- data/gemfiles/rails4.gemfile +1 -6
- data/lib/active_fedora.rb +6 -6
- data/lib/active_fedora/associations/association_scope.rb +1 -1
- data/lib/active_fedora/base.rb +2 -0
- data/lib/active_fedora/datastream.rb +29 -2
- data/lib/active_fedora/datastream_collections.rb +2 -2
- data/lib/active_fedora/datastream_hash.rb +1 -1
- data/lib/active_fedora/datastreams.rb +4 -23
- data/lib/active_fedora/file_configurator.rb +8 -7
- data/lib/active_fedora/om_datastream.rb +1 -1
- data/lib/active_fedora/rdf.rb +9 -0
- data/lib/active_fedora/rdf/configurable.rb +59 -0
- data/lib/active_fedora/rdf/identifiable.rb +59 -0
- data/lib/active_fedora/rdf/indexing.rb +24 -23
- data/lib/active_fedora/rdf/list.rb +154 -0
- data/lib/active_fedora/{ntriples_rdf_datastream.rb → rdf/ntriples_rdf_datastream.rb} +0 -0
- data/lib/active_fedora/rdf/object_resource.rb +20 -0
- data/lib/active_fedora/rdf/properties.rb +108 -0
- data/lib/active_fedora/rdf/rdf_datastream.rb +113 -0
- data/lib/active_fedora/{rdfxml_rdf_datastream.rb → rdf/rdfxml_rdf_datastream.rb} +0 -0
- data/lib/active_fedora/rdf/repositories.rb +36 -0
- data/lib/active_fedora/rdf/resource.rb +324 -0
- data/lib/active_fedora/rdf/term.rb +188 -0
- data/lib/active_fedora/relation.rb +1 -0
- data/lib/active_fedora/relation/finder_methods.rb +16 -17
- data/lib/active_fedora/relation/merger.rb +1 -1
- data/lib/active_fedora/relation/query_methods.rb +13 -5
- data/lib/active_fedora/reload_on_save.rb +16 -0
- data/lib/active_fedora/rubydora_connection.rb +0 -1
- data/lib/active_fedora/sharding.rb +1 -1
- data/lib/active_fedora/version.rb +1 -1
- data/script/console +10 -11
- data/spec/config_helper.rb +1 -1
- data/spec/fixtures/solr_rdf_descMetadata.nt +1 -1
- data/spec/integration/auditable_spec.rb +1 -1
- data/spec/integration/base_spec.rb +21 -3
- data/spec/integration/complex_rdf_datastream_spec.rb +32 -55
- data/spec/integration/field_to_solr_name_spec.rb +6 -8
- data/spec/integration/has_many_associations_spec.rb +10 -3
- data/spec/integration/load_from_solr_spec.rb +15 -17
- data/spec/integration/ntriples_datastream_spec.rb +19 -23
- data/spec/integration/om_datastream_spec.rb +1 -1
- data/spec/integration/rdf_nested_attributes_spec.rb +51 -70
- data/spec/integration/relation_spec.rb +24 -11
- data/spec/integration/scoped_query_spec.rb +5 -1
- data/spec/samples/hydra-mods_article_datastream.rb +4 -0
- data/spec/samples/hydra-rights_metadata_datastream.rb +5 -0
- data/spec/samples/marpa-dc_datastream.rb +6 -1
- data/spec/samples/special_thing.rb +5 -5
- data/spec/spec_helper.rb +0 -3
- data/spec/support/an_active_model.rb +5 -12
- data/spec/unit/active_fedora_spec.rb +2 -2
- data/spec/unit/attributes_spec.rb +4 -8
- data/spec/unit/base_datastream_management_spec.rb +5 -29
- data/spec/unit/base_spec.rb +4 -0
- data/spec/unit/code_configurator_spec.rb +2 -2
- data/spec/unit/config_spec.rb +2 -2
- data/spec/unit/core_spec.rb +2 -4
- data/spec/unit/datastream_spec.rb +15 -0
- data/spec/unit/datastreams_spec.rb +1 -12
- data/spec/unit/file_configurator_spec.rb +1 -1
- data/spec/unit/ntriples_datastream_spec.rb +52 -57
- data/spec/unit/om_datastream_spec.rb +3 -3
- data/spec/unit/query_spec.rb +3 -4
- data/spec/unit/rdf_configurable_spec.rb +37 -0
- data/spec/unit/rdf_datastream_spec.rb +5 -7
- data/spec/unit/rdf_list_nested_attributes_spec.rb +22 -36
- data/spec/unit/rdf_list_spec.rb +26 -38
- data/spec/unit/rdf_properties_spec.rb +70 -0
- data/spec/unit/rdf_repositories_spec.rb +28 -0
- data/spec/unit/rdf_resource_datastream_spec.rb +287 -0
- data/spec/unit/rdf_resource_spec.rb +341 -0
- data/spec/unit/rdfxml_rdf_datastream_spec.rb +10 -26
- data/spec/unit/reload_on_save_spec.rb +24 -0
- data/spec/unit/solr_service_spec.rb +3 -3
- metadata +45 -16
- data/lib/active_fedora/rdf_datastream.rb +0 -113
- data/lib/active_fedora/rdf_list.rb +0 -162
- data/lib/active_fedora/rdf_node.rb +0 -332
- data/lib/active_fedora/rdf_node/term_proxy.rb +0 -141
- data/lib/active_fedora/rdf_object.rb +0 -24
- data/lib/active_fedora/yaml_adaptor.rb +0 -12
- data/spec/unit/rdf_node_spec.rb +0 -36
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 227fe9f2bd7222d69978ee4274e4be82f7d8f801
|
4
|
+
data.tar.gz: b12967fce3d7391ef17032c9ee105581a21efe85
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1e3c90b8b1ff58175a17ea84c1bb72671ae9c0d14bbcb944e0e542d89af4de8e2d36ab938bdbb314aa203f4908f6da6a75738b4973ced0c2ce02e879607b1f36
|
7
|
+
data.tar.gz: 048679b8db7f8393a59cd04c7dd0b5b04b7b5fe1988d0997abbdffc3d3d603aa30ed14e58171ebc46cb7fd51d39c605f2db58a6af2c29f84a4624ba81b86c0d5
|
data/.travis.yml
CHANGED
@@ -1,12 +1,22 @@
|
|
1
1
|
language: ruby
|
2
2
|
rvm:
|
3
|
-
- 2.1.
|
4
|
-
- 2.0.0
|
5
|
-
- 1.9.3
|
3
|
+
- 2.1.1
|
6
4
|
|
7
5
|
gemfile:
|
8
6
|
- gemfiles/rails3.gemfile
|
9
7
|
- gemfiles/rails4.gemfile
|
8
|
+
- gemfiles/rails4.1.gemfile
|
9
|
+
|
10
|
+
|
11
|
+
matrix:
|
12
|
+
include:
|
13
|
+
- rvm: 2.1.0
|
14
|
+
gemfile: gemfiles/rails4.gemfile
|
15
|
+
- rvm: 2.0.0
|
16
|
+
gemfile: gemfiles/rails4.gemfile
|
17
|
+
- rvm: 1.9.3
|
18
|
+
gemfile: gemfiles/rails4.gemfile
|
19
|
+
|
10
20
|
|
11
21
|
notifications:
|
12
22
|
irc: "irc.freenode.org#projecthydra"
|
data/CONTRIBUTORS.md
CHANGED
data/Gemfile
CHANGED
@@ -4,9 +4,8 @@ source "https://rubygems.org"
|
|
4
4
|
|
5
5
|
gemspec
|
6
6
|
|
7
|
-
group :
|
8
|
-
gem 'simplecov', :
|
9
|
-
gem 'simplecov-rcov', :platforms => [:mri_19]#, :mri_20]
|
7
|
+
group :test do
|
8
|
+
gem 'simplecov', require: false
|
10
9
|
end
|
11
10
|
|
12
11
|
gem 'jruby-openssl', :platform=> :jruby
|
data/active-fedora.gemspec
CHANGED
@@ -19,8 +19,8 @@ Gem::Specification.new do |s|
|
|
19
19
|
s.add_dependency('nom-xml', '>=0.5.1')
|
20
20
|
s.add_dependency("activesupport", '>= 3.0.0')
|
21
21
|
s.add_dependency("mediashelf-loggable")
|
22
|
-
s.add_dependency("rubydora", '~>1.7.
|
23
|
-
s.add_dependency("
|
22
|
+
s.add_dependency("rubydora", '~>1.7.4')
|
23
|
+
s.add_dependency("linkeddata")
|
24
24
|
s.add_dependency("rdf-rdfxml", '~>1.1.0')
|
25
25
|
s.add_dependency("deprecation")
|
26
26
|
s.add_development_dependency("rdoc")
|
@@ -31,7 +31,8 @@ Gem::Specification.new do |s|
|
|
31
31
|
s.add_development_dependency("equivalent-xml")
|
32
32
|
s.add_development_dependency("rest-client")
|
33
33
|
s.add_development_dependency("webmock")
|
34
|
-
|
34
|
+
s.add_development_dependency("simplecov", '~> 0.7.1')
|
35
|
+
|
35
36
|
s.files = `git ls-files`.split("\n")
|
36
37
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
37
38
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
data/gemfiles/rails3.gemfile
CHANGED
@@ -1,11 +1,5 @@
|
|
1
|
-
source "
|
1
|
+
source "https://rubygems.org"
|
2
2
|
|
3
3
|
gemspec :path=>"../"
|
4
4
|
|
5
5
|
gem 'activemodel', '~> 3.2.13'
|
6
|
-
|
7
|
-
group :development, :test do
|
8
|
-
gem 'rcov', :platform => :mri_18
|
9
|
-
gem 'simplecov', :platform => :mri_19
|
10
|
-
gem 'simplecov-rcov', :platform => :mri_19
|
11
|
-
end
|
data/gemfiles/rails4.gemfile
CHANGED
data/lib/active_fedora.rb
CHANGED
@@ -47,7 +47,6 @@ module ActiveFedora #:nodoc:
|
|
47
47
|
autoload :Model
|
48
48
|
autoload :NestedAttributes
|
49
49
|
autoload :NomDatastream
|
50
|
-
autoload :NtriplesRDFDatastream
|
51
50
|
autoload :NullRelation
|
52
51
|
autoload :OmDatastream
|
53
52
|
autoload :Property
|
@@ -55,13 +54,14 @@ module ActiveFedora #:nodoc:
|
|
55
54
|
autoload :QualifiedDublinCoreDatastream
|
56
55
|
autoload :Querying
|
57
56
|
autoload :Rdf
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
57
|
+
autoload_under 'rdf' do
|
58
|
+
autoload :RDFDatastream
|
59
|
+
autoload :RdfxmlRDFDatastream
|
60
|
+
autoload :NtriplesRDFDatastream
|
61
|
+
end
|
63
62
|
autoload :Reflection
|
64
63
|
autoload :Relation
|
64
|
+
autoload :ReloadOnSave
|
65
65
|
|
66
66
|
autoload_under 'relation' do
|
67
67
|
autoload :Calculations
|
@@ -23,7 +23,7 @@ module ActiveFedora
|
|
23
23
|
if reflection.source_macro == :belongs_to
|
24
24
|
elsif reflection.source_macro == :has_and_belongs_to_many
|
25
25
|
else
|
26
|
-
scope = scope.where( association.send(:find_predicate) => owner.internal_uri)
|
26
|
+
scope = scope.where( ActiveFedora::SolrService.construct_query_for_rel(association.send(:find_predicate) => owner.internal_uri))
|
27
27
|
end
|
28
28
|
|
29
29
|
|
data/lib/active_fedora/base.rb
CHANGED
@@ -6,9 +6,21 @@ module ActiveFedora
|
|
6
6
|
attr_writer :digital_object
|
7
7
|
attr_accessor :last_modified
|
8
8
|
|
9
|
+
# @param digital_object [DigitalObject] the digital object that this object belongs to
|
10
|
+
# @param dsid [String] the datastream id, if this is nil, a datastream id will be generated.
|
11
|
+
# @param options [Hash]
|
12
|
+
# @option options [String,IO] :content the content for the datastream
|
13
|
+
# @option options [String] :dsLabel label for the datastream
|
14
|
+
# @option options [String] :dsLocation location for an external or redirect datastream
|
15
|
+
# @option options [String] :controlGroup a controlGroup for the datastream
|
16
|
+
# @option options [String] :mimeType the mime-type of the content
|
17
|
+
# @option options [String] :prefix the prefix for the auto-generated DSID (not to be confused with the solr prefix)
|
18
|
+
# @option options [Boolean] :versionable is the datastream versionable
|
9
19
|
def initialize(digital_object=nil, dsid=nil, options={})
|
10
|
-
|
11
|
-
|
20
|
+
prefix = options.delete(:prefix)
|
21
|
+
dsid = nil if dsid == ''
|
22
|
+
dsid ||= generate_dsid(digital_object, prefix || "DS")
|
23
|
+
super(digital_object, dsid, options)
|
12
24
|
end
|
13
25
|
|
14
26
|
alias_method :realLabel, :label
|
@@ -81,6 +93,21 @@ module ActiveFedora
|
|
81
93
|
end
|
82
94
|
|
83
95
|
protected
|
96
|
+
|
97
|
+
# return a valid dsid that is not currently in use. Uses a prefix (default "DS") and an auto-incrementing integer
|
98
|
+
# Example: if there are already datastreams with IDs DS1 and DS2, this method will return DS3. If you specify FOO as the prefix, it will return FOO1.
|
99
|
+
def generate_dsid(digital_object, prefix)
|
100
|
+
return unless digital_object
|
101
|
+
matches = digital_object.datastreams.keys.map {|d| data = /^#{prefix}(\d+)$/.match(d); data && data[1].to_i}.compact
|
102
|
+
val = matches.empty? ? 1 : matches.max + 1
|
103
|
+
format_dsid(prefix, val)
|
104
|
+
end
|
105
|
+
|
106
|
+
### Provided so that an application can override how generated pids are formatted (e.g DS01 instead of DS1)
|
107
|
+
def format_dsid(prefix, suffix)
|
108
|
+
sprintf("%s%i", prefix,suffix)
|
109
|
+
end
|
110
|
+
|
84
111
|
# The string to prefix all solr fields with. Override this method if you want
|
85
112
|
# a prefix other than the default
|
86
113
|
def prefix
|
@@ -215,8 +215,8 @@ module ActiveFedora
|
|
215
215
|
assert_kind_of 'datastream', ds, ActiveFedora::Datastream
|
216
216
|
#make sure dsid is nil so that it uses the prefix for mapping purposes
|
217
217
|
#check dsid works for the prefix if it is set
|
218
|
-
if
|
219
|
-
raise "dsid supplied does not conform to pattern #{opts[:prefix]}[number]" unless ds.dsid =~ /#{opts[:prefix]}[0-9]/
|
218
|
+
if ds.dsid && opts.has_key?(:prefix)
|
219
|
+
raise "dsid supplied (#{ds.dsid}) does not conform to pattern #{opts[:prefix]}[number]" unless ds.dsid =~ /#{opts[:prefix]}[0-9]/
|
220
220
|
end
|
221
221
|
|
222
222
|
add_datastream(ds,opts)
|
@@ -2,7 +2,7 @@ module ActiveFedora
|
|
2
2
|
module Datastreams
|
3
3
|
extend ActiveSupport::Concern
|
4
4
|
|
5
|
-
autoload :NokogiriDatastreams,
|
5
|
+
autoload :NokogiriDatastreams, 'active_fedora/datastreams/nokogiri_datastreams'
|
6
6
|
|
7
7
|
included do
|
8
8
|
class_attribute :ds_specs
|
@@ -81,15 +81,9 @@ module ActiveFedora
|
|
81
81
|
end
|
82
82
|
end
|
83
83
|
|
84
|
-
# Adds datastream to the object.
|
85
|
-
# If datastream does not have a DSID, a unique DSID is generated
|
86
|
-
# :prefix option will set the prefix on auto-generated DSID
|
84
|
+
# Adds datastream to the object.
|
87
85
|
# @return [String] dsid of the added datastream
|
88
86
|
def add_datastream(datastream, opts={})
|
89
|
-
if datastream.dsid == nil || datastream.dsid.empty?
|
90
|
-
prefix = opts.has_key?(:prefix) ? opts[:prefix] : "DS"
|
91
|
-
datastream.instance_variable_set :@dsid, generate_dsid(prefix)
|
92
|
-
end
|
93
87
|
datastreams[datastream.dsid] = datastream
|
94
88
|
datastream.dsid
|
95
89
|
end
|
@@ -99,18 +93,6 @@ module ActiveFedora
|
|
99
93
|
datastreams.select { |k, ds| ds.metadata? }.reject { |k, ds| ds.kind_of?(ActiveFedora::RelsExtDatastream) }.values
|
100
94
|
end
|
101
95
|
|
102
|
-
# return a valid dsid that is not currently in use. Uses a prefix (default "DS") and an auto-incrementing integer
|
103
|
-
# Example: if there are already datastreams with IDs DS1 and DS2, this method will return DS3. If you specify FOO as the prefix, it will return FOO1.
|
104
|
-
def generate_dsid(prefix="DS")
|
105
|
-
matches = datastreams.keys.map {|d| data = /^#{prefix}(\d+)$/.match(d); data && data[1].to_i}.compact
|
106
|
-
val = matches.empty? ? 1 : matches.max + 1
|
107
|
-
format_dsid(prefix, val)
|
108
|
-
end
|
109
|
-
|
110
|
-
### Provided so that an application can override how generated pids are formatted (e.g DS01 instead of DS1)
|
111
|
-
def format_dsid(prefix, suffix)
|
112
|
-
sprintf("%s%i", prefix,suffix)
|
113
|
-
end
|
114
96
|
|
115
97
|
# Returns the RELS-EXT Datastream
|
116
98
|
# Tries to grab from in-memory datastreams first
|
@@ -153,10 +135,9 @@ module ActiveFedora
|
|
153
135
|
|
154
136
|
|
155
137
|
def create_datastream(type, dsid, opts={})
|
156
|
-
dsid ||= generate_dsid(opts[:prefix] || "DS")
|
157
138
|
klass = type.kind_of?(Class) ? type : type.constantize
|
158
|
-
raise ArgumentError, "Argument dsid must be of type string"
|
159
|
-
ds = klass.new(inner_object, dsid)
|
139
|
+
raise ArgumentError, "Argument dsid must be of type string" if dsid && !dsid.kind_of?(String)
|
140
|
+
ds = klass.new(inner_object, dsid, prefix: opts[:prefix])
|
160
141
|
[:mimeType, :controlGroup, :dsLabel, :dsLocation, :checksumType, :versionable].each do |key|
|
161
142
|
ds.send("#{key}=".to_sym, opts[key]) unless opts[key].nil?
|
162
143
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'erb'
|
2
|
-
require '
|
2
|
+
require 'yaml'
|
3
3
|
|
4
4
|
module ActiveFedora
|
5
5
|
class FileConfigurator
|
@@ -110,9 +110,10 @@ module ActiveFedora
|
|
110
110
|
end
|
111
111
|
|
112
112
|
begin
|
113
|
-
fedora_yml =
|
114
|
-
rescue
|
115
|
-
raise
|
113
|
+
fedora_yml = YAML.load(config_erb)
|
114
|
+
rescue Psych::SyntaxError => e
|
115
|
+
raise "fedora.yml was found, but could not be parsed. " \
|
116
|
+
"Error #{e.message}"
|
116
117
|
end
|
117
118
|
|
118
119
|
config = fedora_yml.symbolize_keys
|
@@ -133,7 +134,7 @@ module ActiveFedora
|
|
133
134
|
end
|
134
135
|
|
135
136
|
begin
|
136
|
-
solr_yml =
|
137
|
+
solr_yml = YAML.load(config_erb)
|
137
138
|
rescue StandardError => e
|
138
139
|
raise("solr.yml was found, but could not be parsed.\n")
|
139
140
|
end
|
@@ -209,7 +210,7 @@ module ActiveFedora
|
|
209
210
|
|
210
211
|
def predicate_config
|
211
212
|
@predicate_config_path ||= build_predicate_config_path
|
212
|
-
|
213
|
+
YAML.load(File.open(@predicate_config_path)) if File.exist?(@predicate_config_path)
|
213
214
|
end
|
214
215
|
|
215
216
|
protected
|
@@ -223,7 +224,7 @@ module ActiveFedora
|
|
223
224
|
end
|
224
225
|
|
225
226
|
def valid_predicate_mapping?(testfile)
|
226
|
-
mapping =
|
227
|
+
mapping = YAML.load(File.open(testfile))
|
227
228
|
return false unless mapping.has_key?(:default_namespace) && mapping[:default_namespace].is_a?(String)
|
228
229
|
return false unless mapping.has_key?(:predicate_mapping) && mapping[:predicate_mapping].is_a?(Hash)
|
229
230
|
true
|
@@ -186,7 +186,7 @@ module ActiveFedora
|
|
186
186
|
end
|
187
187
|
|
188
188
|
def generate_solr_symbol(base, data_type)
|
189
|
-
ActiveFedora::SolrService.solr_name(base.
|
189
|
+
ActiveFedora::SolrService.solr_name([prefix,base].join, type: data_type)
|
190
190
|
end
|
191
191
|
|
192
192
|
# ** Experimental **
|
data/lib/active_fedora/rdf.rb
CHANGED
@@ -4,5 +4,14 @@ module ActiveFedora
|
|
4
4
|
autoload :NestedAttributes
|
5
5
|
autoload :NodeConfig
|
6
6
|
autoload :Indexing
|
7
|
+
autoload :Configurable
|
8
|
+
autoload :Properties
|
9
|
+
autoload :Identifiable
|
10
|
+
autoload :Repositories
|
11
|
+
autoload :Resource
|
12
|
+
autoload :VocabularyLoader
|
13
|
+
autoload :ObjectResource
|
14
|
+
autoload :Term
|
15
|
+
autoload :List
|
7
16
|
end
|
8
17
|
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
module ActiveFedora::Rdf
|
2
|
+
##
|
3
|
+
# Module to include configurable class-wide properties common to
|
4
|
+
# Resource and RDFDatastream. It does its work at the class level,
|
5
|
+
# and is meant to be extended.
|
6
|
+
#
|
7
|
+
# Define properties at the class level with:
|
8
|
+
#
|
9
|
+
# configure base_uri: "http://oregondigital.org/resource/", repository: :parent
|
10
|
+
# Available properties are base_uri, rdf_label, type, and repository
|
11
|
+
module Configurable
|
12
|
+
extend Deprecation
|
13
|
+
|
14
|
+
def base_uri
|
15
|
+
nil
|
16
|
+
end
|
17
|
+
|
18
|
+
def rdf_label
|
19
|
+
nil
|
20
|
+
end
|
21
|
+
|
22
|
+
def type
|
23
|
+
nil
|
24
|
+
end
|
25
|
+
|
26
|
+
def rdf_type(value)
|
27
|
+
Deprecation.warn Configurable, "rdf_type is deprecated and will be removed in active-fedora 8.0.0. Use configure type: instead.", caller
|
28
|
+
configure type: value
|
29
|
+
end
|
30
|
+
|
31
|
+
def repository
|
32
|
+
:parent
|
33
|
+
end
|
34
|
+
|
35
|
+
# API method for configuring class properties an RDF Resource may need.
|
36
|
+
# This is an alternative to overriding the methods extended with this module.
|
37
|
+
def configure(options = {})
|
38
|
+
{
|
39
|
+
base_uri: options[:base_uri],
|
40
|
+
rdf_label: options[:rdf_label],
|
41
|
+
type: options[:type],
|
42
|
+
repository: options[:repository]
|
43
|
+
}.each do |name, value|
|
44
|
+
if value
|
45
|
+
value = self.send("transform_#{name}", value) if self.respond_to?("transform_#{name}")
|
46
|
+
define_singleton_method(name) do
|
47
|
+
value
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def transform_type(value)
|
54
|
+
RDF::URI.new(value).tap do |value|
|
55
|
+
Resource.type_registry[value] = self
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
##
|
2
|
+
# This module is included to allow for an ActiveFedora::Base object to be set as the class_name for a Resource.
|
3
|
+
# Enables functionality like:
|
4
|
+
# base = ActiveFedora::Base.new('oregondigital:1')
|
5
|
+
# base.title = 'test'
|
6
|
+
# base.save
|
7
|
+
# subject.descMetadata.set = base
|
8
|
+
# subject.descMetadata.set # => <ActiveFedora::Base>
|
9
|
+
# subject.descMetadata.set.title # => 'test'
|
10
|
+
module ActiveFedora::Rdf::Identifiable
|
11
|
+
extend ActiveSupport::Concern
|
12
|
+
delegate :parent, :dump, :query, :rdf_type, :to => :resource
|
13
|
+
|
14
|
+
##
|
15
|
+
# Defines which resource defines this ActiveFedora object.
|
16
|
+
# This is required for ActiveFedora::Rdf::Resource#set_value to append graphs.
|
17
|
+
# If there is no RdfResource, make a dummy one and freeze its graph.
|
18
|
+
def resource
|
19
|
+
return self.send(self.class.resource_datastream).resource unless self.class.resource_datastream.nil?
|
20
|
+
ActiveFedora::Rdf::ObjectResource.new(self.pid).freeze
|
21
|
+
end
|
22
|
+
|
23
|
+
module ClassMethods
|
24
|
+
##
|
25
|
+
# Returns the datastream whose ActiveFedora::Rdf::Resource is used
|
26
|
+
# for the identifiable object. This supports delegating methods to
|
27
|
+
# the Resource and #from_uri. Defaults to :descMetadata if it
|
28
|
+
# responds to #rdf_subject, otherwise looks for the first
|
29
|
+
# registered datastream that does.
|
30
|
+
def resource_datastream(ds=nil)
|
31
|
+
@resource_datastream ||= ds ? ds : nil
|
32
|
+
return @resource_datastream unless @resource_datastream.nil?
|
33
|
+
return :descMetadata if self.ds_specs['descMetadata'][:type].respond_to? :rdf_subject
|
34
|
+
self.ds_specs.each do |dsid, conf|
|
35
|
+
return dsid.to_sym if conf[:type].respond_to? :rdf_subject
|
36
|
+
end
|
37
|
+
nil
|
38
|
+
end
|
39
|
+
|
40
|
+
##
|
41
|
+
# Finds the appropriate ActiveFedora::Base object given a URI from a graph.
|
42
|
+
# Expected by the API in ActiveFedora::Rdf::Resource
|
43
|
+
# @TODO: Generalize this.
|
44
|
+
# @see ActiveFedora::Rdf::Resource.from_uri
|
45
|
+
# @param [RDF::URI] uri URI that is being looked up.
|
46
|
+
def from_uri(uri,_)
|
47
|
+
self.find(pid_from_subject(uri))
|
48
|
+
end
|
49
|
+
|
50
|
+
##
|
51
|
+
# Finds the pid of an object from its RDF subject, override this
|
52
|
+
# for URI configurations not of form base_uri + pid
|
53
|
+
# @param [RDF::URI] uri URI to convert to pid
|
54
|
+
def pid_from_subject(uri)
|
55
|
+
base_uri = resource_datastream ? self.ds_specs[resource_datastream.to_s][:type].resource_class.base_uri : ActiveFedora::Rdf::ObjectResource.base_uri
|
56
|
+
uri.to_s.gsub(base_uri, "")
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|