active-fedora 13.3.0 → 14.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +106 -46
- data/.rubocop.yml +26 -12
- data/.rubocop_todo.yml +1 -1
- data/Gemfile +3 -3
- data/active-fedora.gemspec +11 -11
- data/lib/active_fedora/association_hash.rb +5 -2
- data/lib/active_fedora/associations/association.rb +2 -4
- data/lib/active_fedora/associations/association_scope.rb +1 -1
- data/lib/active_fedora/associations/basic_contains_association.rb +2 -2
- data/lib/active_fedora/associations/belongs_to_association.rb +1 -1
- data/lib/active_fedora/associations/builder/association.rb +3 -5
- data/lib/active_fedora/associations/builder/basic_contains.rb +1 -1
- data/lib/active_fedora/associations/builder/belongs_to.rb +3 -7
- data/lib/active_fedora/associations/builder/collection_association.rb +7 -7
- data/lib/active_fedora/associations/builder/directly_contains.rb +4 -6
- data/lib/active_fedora/associations/builder/directly_contains_one.rb +5 -6
- data/lib/active_fedora/associations/builder/has_and_belongs_to_many.rb +1 -1
- data/lib/active_fedora/associations/builder/has_many.rb +1 -1
- data/lib/active_fedora/associations/builder/has_subresource.rb +1 -1
- data/lib/active_fedora/associations/builder/indirectly_contains.rb +3 -6
- data/lib/active_fedora/associations/builder/singular_association.rb +1 -1
- data/lib/active_fedora/associations/collection_association.rb +3 -6
- data/lib/active_fedora/associations/container_proxy.rb +2 -0
- data/lib/active_fedora/associations/contains_association.rb +2 -2
- data/lib/active_fedora/associations/directly_contains_association.rb +7 -9
- data/lib/active_fedora/associations/directly_contains_one_association.rb +2 -2
- data/lib/active_fedora/associations/has_and_belongs_to_many_association.rb +1 -1
- data/lib/active_fedora/associations/has_many_association.rb +4 -2
- data/lib/active_fedora/associations/has_subresource_association.rb +2 -4
- data/lib/active_fedora/associations/indirectly_contains_association.rb +10 -12
- data/lib/active_fedora/associations/orders_association.rb +7 -14
- data/lib/active_fedora/associations/rdf.rb +2 -2
- data/lib/active_fedora/associations/record_composite.rb +1 -0
- data/lib/active_fedora/associations/singular_association.rb +3 -1
- data/lib/active_fedora/associations/singular_rdf.rb +1 -1
- data/lib/active_fedora/associations.rb +3 -3
- data/lib/active_fedora/attached_files.rb +5 -3
- data/lib/active_fedora/attribute_assignment.rb +2 -4
- data/lib/active_fedora/attribute_methods/read.rb +1 -1
- data/lib/active_fedora/attribute_methods/write.rb +4 -6
- data/lib/active_fedora/attribute_methods.rb +7 -7
- data/lib/active_fedora/attributes/property_builder.rb +1 -1
- data/lib/active_fedora/attributes.rb +1 -1
- data/lib/active_fedora/autosave_association.rb +4 -4
- data/lib/active_fedora/callbacks.rb +3 -3
- data/lib/active_fedora/change_set.rb +5 -7
- data/lib/active_fedora/cleaner.rb +1 -1
- data/lib/active_fedora/core/fedora_id_translator.rb +1 -3
- data/lib/active_fedora/core.rb +6 -13
- data/lib/active_fedora/errors.rb +3 -3
- data/lib/active_fedora/fedora.rb +3 -7
- data/lib/active_fedora/file/attributes.rb +5 -5
- data/lib/active_fedora/file.rb +1 -1
- data/lib/active_fedora/file_configurator.rb +16 -14
- data/lib/active_fedora/file_io.rb +2 -4
- data/lib/active_fedora/files_hash.rb +2 -2
- data/lib/active_fedora/fixity_service.rb +5 -5
- data/lib/active_fedora/identifiable.rb +2 -18
- data/lib/active_fedora/indexing/default_descriptors.rb +3 -5
- data/lib/active_fedora/indexing/descendant_fetcher.rb +3 -3
- data/lib/active_fedora/indexing/descriptor.rb +1 -1
- data/lib/active_fedora/indexing/field_mapper.rb +3 -5
- data/lib/active_fedora/indexing.rb +9 -5
- data/lib/active_fedora/indexing_service.rb +2 -2
- data/lib/active_fedora/inheritance.rb +1 -3
- data/lib/active_fedora/ldp_resource.rb +3 -3
- data/lib/active_fedora/loadable_from_json.rb +5 -3
- data/lib/active_fedora/model_classifier.rb +2 -2
- data/lib/active_fedora/nested_attributes.rb +11 -21
- data/lib/active_fedora/null_logger.rb +2 -0
- data/lib/active_fedora/orders/list_node.rb +2 -3
- data/lib/active_fedora/orders/ordered_list.rb +16 -22
- data/lib/active_fedora/orders/target_proxy.rb +1 -1
- data/lib/active_fedora/querying.rb +1 -1
- data/lib/active_fedora/rdf/fcrepo.rb +3 -0
- data/lib/active_fedora/rdf/field_map.rb +0 -1
- data/lib/active_fedora/rdf/persistence.rb +1 -1
- data/lib/active_fedora/reflection.rb +8 -11
- data/lib/active_fedora/relation/finder_methods.rb +6 -12
- data/lib/active_fedora/relation/spawn_methods.rb +1 -1
- data/lib/active_fedora/runtime_registry.rb +2 -4
- data/lib/active_fedora/scoping/default.rb +2 -4
- data/lib/active_fedora/scoping/named.rb +1 -3
- data/lib/active_fedora/scoping.rb +2 -2
- data/lib/active_fedora/serialization.rb +1 -1
- data/lib/active_fedora/solr_service.rb +1 -3
- data/lib/active_fedora/version.rb +1 -1
- data/lib/active_fedora/versionable.rb +2 -2
- data/lib/active_fedora/versions_graph.rb +4 -6
- data/lib/active_fedora/with_metadata/metadata_node.rb +1 -1
- data/lib/active_fedora/with_metadata.rb +1 -1
- data/lib/active_fedora.rb +5 -7
- data/lib/generators/active_fedora/config/solr/templates/solr/conf/solrconfig.xml +3 -1
- data/lib/tasks/active_fedora_dev.rake +5 -5
- metadata +25 -52
@@ -1,6 +1,6 @@
|
|
1
1
|
module ActiveFedora
|
2
2
|
module Associations
|
3
|
-
class CollectionAssociation < Association
|
3
|
+
class CollectionAssociation < Association # :nodoc:
|
4
4
|
attr_reader :proxy
|
5
5
|
|
6
6
|
# Implements the reader method, e.g. foo.items for Foo.has_many :items
|
@@ -336,11 +336,8 @@ module ActiveFedora
|
|
336
336
|
|
337
337
|
def find_reflection
|
338
338
|
return reflection if @reflection.options[:predicate]
|
339
|
-
|
340
|
-
|
341
|
-
else
|
342
|
-
raise "Couldn't find reflection"
|
343
|
-
end
|
339
|
+
raise "Couldn't find reflection" unless @reflection.class_name && @reflection.class_name != 'ActiveFedora::Base' && @reflection.macro != :has_and_belongs_to_many
|
340
|
+
@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}")
|
344
341
|
end
|
345
342
|
|
346
343
|
def _create_record(attributes, raise = false)
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# This is the parent class of BasicContainsAssociation, DirectlyContainsAssociation and IndirectlyContainsAssociation
|
2
2
|
module ActiveFedora
|
3
3
|
module Associations
|
4
|
-
class ContainsAssociation < CollectionAssociation
|
4
|
+
class ContainsAssociation < CollectionAssociation # :nodoc:
|
5
5
|
def insert_record(record, force = true, validate = true)
|
6
6
|
if force
|
7
7
|
record.save!
|
@@ -18,7 +18,7 @@ module ActiveFedora
|
|
18
18
|
if loaded?
|
19
19
|
target.include?(other)
|
20
20
|
elsif container_predicate = options[:has_member_relation]
|
21
|
-
owner.resource.query(predicate: container_predicate, object: ::RDF::URI(other.uri)).present?
|
21
|
+
owner.resource.query({ predicate: container_predicate, object: ::RDF::URI(other.uri) }).present?
|
22
22
|
else # is_member_of_relation
|
23
23
|
# This will force a load, so it's slowest and the least preferable option
|
24
24
|
target.include?(other)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module ActiveFedora
|
2
2
|
module Associations
|
3
|
-
class DirectlyContainsAssociation < ContainsAssociation
|
3
|
+
class DirectlyContainsAssociation < ContainsAssociation # :nodoc:
|
4
4
|
def insert_record(record, force = true, validate = true)
|
5
5
|
container.save!
|
6
6
|
super
|
@@ -14,24 +14,22 @@ module ActiveFedora
|
|
14
14
|
container
|
15
15
|
end
|
16
16
|
|
17
|
-
uris = query_node.resource.query(predicate: container_predicate).map { |r| r.object.to_s }
|
17
|
+
uris = query_node.resource.query({ predicate: container_predicate }).map { |r| r.object.to_s }
|
18
18
|
|
19
19
|
uris.map { |object_uri| klass.find(klass.uri_to_id(object_uri)) }
|
20
20
|
end
|
21
21
|
|
22
22
|
def container
|
23
|
-
@container ||=
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
container.is_member_of_relation = Array(options[:is_member_of_relation])
|
28
|
-
end
|
23
|
+
@container ||= DirectContainer.find_or_initialize(ActiveFedora::Base.uri_to_id(uri)).tap do |container|
|
24
|
+
container.parent = @owner
|
25
|
+
container.has_member_relation = Array(options[:has_member_relation])
|
26
|
+
container.is_member_of_relation = Array(options[:is_member_of_relation])
|
29
27
|
end
|
30
28
|
end
|
31
29
|
|
32
30
|
protected
|
33
31
|
|
34
|
-
def initialize_attributes(record)
|
32
|
+
def initialize_attributes(record) # :nodoc:
|
35
33
|
record.uri = ActiveFedora::Base.id_to_uri(container.mint_id)
|
36
34
|
set_inverse_instance(record)
|
37
35
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module ActiveFedora
|
2
2
|
module Associations
|
3
3
|
# Filters a DirectContainer relationship, returning the first item that matches the given :type
|
4
|
-
class DirectlyContainsOneAssociation < SingularAssociation
|
4
|
+
class DirectlyContainsOneAssociation < SingularAssociation # :nodoc:
|
5
5
|
# Finds objects contained by the container predicate (either the configured has_member_relation or ldp:contains)
|
6
6
|
# TODO: Refactor this to use solr (for efficiency) instead of parsing the RDF graph. Requires indexing ActiveFedora::File objects into solr, including their RDF.type and, if possible, the id of their container
|
7
7
|
# See https://github.com/samvera/active_fedora/issues/1335
|
@@ -14,7 +14,7 @@ module ActiveFedora
|
|
14
14
|
container_association.container # Use the :through association's container
|
15
15
|
end
|
16
16
|
|
17
|
-
contained_uris = query_node.resource.query(predicate: container_predicate).map { |r| r.object.to_s }
|
17
|
+
contained_uris = query_node.resource.query({ predicate: container_predicate }).map { |r| r.object.to_s }
|
18
18
|
contained_uris.each do |object_uri|
|
19
19
|
contained_object = klass.find(klass.uri_to_id(object_uri))
|
20
20
|
return contained_object if get_type_from_record(contained_object).include?(options[:type])
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module ActiveFedora
|
2
2
|
# = Active Fedora Has And Belongs To Many Association
|
3
3
|
module Associations
|
4
|
-
class HasAndBelongsToManyAssociation < CollectionAssociation
|
4
|
+
class HasAndBelongsToManyAssociation < CollectionAssociation # :nodoc:
|
5
5
|
def initialize(owner, reflection)
|
6
6
|
super
|
7
7
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module ActiveFedora
|
2
2
|
module Associations
|
3
|
-
class HasManyAssociation < CollectionAssociation
|
3
|
+
class HasManyAssociation < CollectionAssociation # :nodoc:
|
4
4
|
def initialize(owner, reflection)
|
5
5
|
super
|
6
6
|
end
|
@@ -35,7 +35,7 @@ module ActiveFedora
|
|
35
35
|
end
|
36
36
|
elsif owner.persisted?
|
37
37
|
inverse = reflection.inverse_of
|
38
|
-
if inverse
|
38
|
+
if inverse&.collection?
|
39
39
|
record[inverse.foreign_key] ||= []
|
40
40
|
record[inverse.foreign_key] += [owner.id]
|
41
41
|
elsif inverse && inverse.klass == ActiveFedora::Base
|
@@ -88,6 +88,7 @@ module ActiveFedora
|
|
88
88
|
|
89
89
|
# Deletes the records according to the <tt>:dependent</tt> option.
|
90
90
|
def delete_records(records, method)
|
91
|
+
# rubocop:disable Style/GuardClause
|
91
92
|
return records.each(&:destroy) if method == :destroy
|
92
93
|
# Find all the records that point to this and nullify them
|
93
94
|
# keys = records.map { |r| r[reflection.association_primary_key] }
|
@@ -115,6 +116,7 @@ module ActiveFedora
|
|
115
116
|
end
|
116
117
|
|
117
118
|
# update_counter(-scope.update_all(reflection.foreign_key => nil))
|
119
|
+
# rubocop:enable Style/GuardClause
|
118
120
|
end
|
119
121
|
end
|
120
122
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module ActiveFedora
|
2
2
|
module Associations
|
3
|
-
class HasSubresourceAssociation < SingularAssociation
|
3
|
+
class HasSubresourceAssociation < SingularAssociation # :nodoc:
|
4
4
|
# Implements the reader method, e.g. foo.bar for Foo.has_one :bar
|
5
5
|
def reader(force_reload = false)
|
6
6
|
super || build
|
@@ -50,9 +50,7 @@ module ActiveFedora
|
|
50
50
|
|
51
51
|
def configure_datastream(record)
|
52
52
|
# If you called has_metadata with a block, pass the block into the File class
|
53
|
-
if reflection.options[:block].class == Proc
|
54
|
-
reflection.options[:block].call(record)
|
55
|
-
end
|
53
|
+
reflection.options[:block].call(record) if reflection.options[:block].class == Proc
|
56
54
|
return unless record.new_record? && reflection.options[:autocreate]
|
57
55
|
record.datastream_will_change!
|
58
56
|
end
|
@@ -3,7 +3,7 @@ module ActiveFedora
|
|
3
3
|
# TODO: we may want to split this into two subclasses, one for has_member_relation
|
4
4
|
# and the other for is_member_of_relation
|
5
5
|
# See https://github.com/samvera/active_fedora/issues/1332
|
6
|
-
class IndirectlyContainsAssociation < ContainsAssociation
|
6
|
+
class IndirectlyContainsAssociation < ContainsAssociation # :nodoc:
|
7
7
|
# Add +records+ to this association. Returns +self+ so method calls may be chained.
|
8
8
|
# Since << flattens its argument list and inserts each record, +push+ and +concat+ behave identically.
|
9
9
|
def concat(*records)
|
@@ -30,38 +30,36 @@ module ActiveFedora
|
|
30
30
|
if loaded?
|
31
31
|
target.map(&:id)
|
32
32
|
else
|
33
|
-
owner.resource.query(predicate: predicate)
|
33
|
+
owner.resource.query({ predicate: predicate })
|
34
34
|
.map { |s| ActiveFedora::Base.uri_to_id(s.object) } | target.map(&:id)
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
38
|
def find_target
|
39
39
|
if container_predicate = options[:has_member_relation]
|
40
|
-
uris = owner.resource.query(predicate: container_predicate).map { |r| r.object.to_s }
|
40
|
+
uris = owner.resource.query({ predicate: container_predicate }).map { |r| r.object.to_s }
|
41
41
|
uris.map { |object_uri| klass.find(klass.uri_to_id(object_uri)) }
|
42
42
|
else # is_member_of_relation
|
43
43
|
# TODO this is a lot of reads. Avoid this path
|
44
44
|
# See https://github.com/samvera/active_fedora/issues/1345
|
45
45
|
container_predicate = ::RDF::Vocab::LDP.contains
|
46
|
-
proxy_uris = container.resource.query(predicate: container_predicate).map { |r| r.object.to_s }
|
46
|
+
proxy_uris = container.resource.query({ predicate: container_predicate }).map { |r| r.object.to_s }
|
47
47
|
proxy_uris.map { |uri| proxy_class.find(proxy_class.uri_to_id(uri))[options[:foreign_key]] }
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
51
51
|
def container
|
52
|
-
@container ||=
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
container.inserted_content_relation = Array(options[:inserted_content_relation])
|
58
|
-
end
|
52
|
+
@container ||= IndirectContainer.find_or_initialize(ActiveFedora::Base.uri_to_id(uri)).tap do |container|
|
53
|
+
container.parent = @owner
|
54
|
+
container.has_member_relation = Array(options[:has_member_relation])
|
55
|
+
container.is_member_of_relation = Array(options[:is_member_of_relation])
|
56
|
+
container.inserted_content_relation = Array(options[:inserted_content_relation])
|
59
57
|
end
|
60
58
|
end
|
61
59
|
|
62
60
|
protected
|
63
61
|
|
64
|
-
def initialize_attributes(_record)
|
62
|
+
def initialize_attributes(_record) # :nodoc:
|
65
63
|
# record.uri = ActiveFedora::Base.id_to_uri(container.mint_id)
|
66
64
|
# set_inverse_instance(record)
|
67
65
|
end
|
@@ -52,9 +52,7 @@ module ActiveFedora::Associations
|
|
52
52
|
# Append a target node to the end of the order.
|
53
53
|
# @param [ActiveFedora::Base] record Record to append
|
54
54
|
def append_target(record, _skip_callbacks = false)
|
55
|
-
unless unordered_association.target.include?(record)
|
56
|
-
unordered_association.concat(record)
|
57
|
-
end
|
55
|
+
unordered_association.concat(record) unless unordered_association.target.include?(record)
|
58
56
|
target.append_target(record, proxy_in: owner)
|
59
57
|
end
|
60
58
|
|
@@ -62,9 +60,7 @@ module ActiveFedora::Associations
|
|
62
60
|
# @param [Integer] loc Position to insert record.
|
63
61
|
# @param [ActiveFedora::Base] record Record to insert
|
64
62
|
def insert_target_at(loc, record)
|
65
|
-
unless unordered_association.target.include?(record)
|
66
|
-
unordered_association.concat(record)
|
67
|
-
end
|
63
|
+
unordered_association.concat(record) unless unordered_association.target.include?(record)
|
68
64
|
target.insert_at(loc, record, proxy_in: owner)
|
69
65
|
end
|
70
66
|
|
@@ -73,9 +69,7 @@ module ActiveFedora::Associations
|
|
73
69
|
# @param [String] id ID of record to insert.
|
74
70
|
def insert_target_id_at(loc, id)
|
75
71
|
raise ArgumentError, "ID can not be nil" if id.nil?
|
76
|
-
unless unordered_association.ids_reader.include?(id)
|
77
|
-
raise ArgumentError, "#{id} is not a part of #{unordered_association.reflection.name}"
|
78
|
-
end
|
72
|
+
raise ArgumentError, "#{id} is not a part of #{unordered_association.reflection.name}" unless unordered_association.ids_reader.include?(id)
|
79
73
|
target.insert_proxy_for_at(loc, ActiveFedora::Base.id_to_uri(id), proxy_in: owner)
|
80
74
|
end
|
81
75
|
|
@@ -106,11 +100,10 @@ module ActiveFedora::Associations
|
|
106
100
|
list_container.save
|
107
101
|
# NOTE: This turns out to be pretty cheap, but should we be doing it
|
108
102
|
# elsewhere?
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
end
|
103
|
+
return if list_container.changed?
|
104
|
+
owner.head = [list_container.head_id.first]
|
105
|
+
owner.tail = [list_container.tail_id.first]
|
106
|
+
owner.save
|
114
107
|
end
|
115
108
|
|
116
109
|
def scope(*_args)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module ActiveFedora
|
2
2
|
module Associations
|
3
|
-
class RDF < SingularAssociation
|
3
|
+
class RDF < SingularAssociation # :nodoc:
|
4
4
|
def replace(values)
|
5
5
|
ids = Array(values).reject(&:blank?)
|
6
6
|
raise "can't modify frozen #{owner.class}" if owner.frozen?
|
@@ -54,7 +54,7 @@ module ActiveFedora
|
|
54
54
|
|
55
55
|
# @return [Array<RDF::Statement>]
|
56
56
|
def rdf_query
|
57
|
-
owner.resource.query(subject: owner.rdf_subject, predicate: reflection.predicate).enum_statement
|
57
|
+
owner.resource.query({ subject: owner.rdf_subject, predicate: reflection.predicate }).enum_statement
|
58
58
|
end
|
59
59
|
|
60
60
|
# @return [Array<RDF::URI>]
|
@@ -1,7 +1,8 @@
|
|
1
1
|
module ActiveFedora
|
2
2
|
module Associations
|
3
|
-
class SingularAssociation < Association
|
3
|
+
class SingularAssociation < Association # :nodoc:
|
4
4
|
# Implements the reader method, e.g. foo.bar for Foo.has_one :bar
|
5
|
+
# rubocop:disable Style/GuardClause
|
5
6
|
def reader(force_reload = false)
|
6
7
|
if force_reload
|
7
8
|
raise NotImplementedError, "Need to define the uncached method" # TODO
|
@@ -11,6 +12,7 @@ module ActiveFedora
|
|
11
12
|
end
|
12
13
|
target
|
13
14
|
end
|
15
|
+
# rubocop:enable Style/GuardClause
|
14
16
|
|
15
17
|
# Implements the writer method, e.g. foo.items= for Foo.has_many :items
|
16
18
|
def writer(record)
|
@@ -3,7 +3,7 @@ require 'active_support/core_ext/module/delegation'
|
|
3
3
|
require 'active_support/core_ext/object/blank'
|
4
4
|
|
5
5
|
module ActiveFedora
|
6
|
-
class InverseOfAssociationNotFoundError < RuntimeError
|
6
|
+
class InverseOfAssociationNotFoundError < RuntimeError # :nodoc:
|
7
7
|
def initialize(reflection, associated_class = nil)
|
8
8
|
super("Could not find the inverse association for #{reflection.name} (#{reflection.options[:inverse_of].inspect} in #{associated_class.nil? ? reflection.class_name : associated_class.name})")
|
9
9
|
end
|
@@ -65,7 +65,7 @@ module ActiveFedora
|
|
65
65
|
end
|
66
66
|
|
67
67
|
# Clears out the association cache.
|
68
|
-
def clear_association_cache
|
68
|
+
def clear_association_cache # :nodoc:
|
69
69
|
@association_cache.clear if persisted?
|
70
70
|
end
|
71
71
|
|
@@ -73,7 +73,7 @@ module ActiveFedora
|
|
73
73
|
attr_reader :association_cache
|
74
74
|
|
75
75
|
# Returns the association instance for the given name, instantiating it if it doesn't already exist
|
76
|
-
def association(name)
|
76
|
+
def association(name) # :nodoc:
|
77
77
|
association = association_instance_get(name)
|
78
78
|
|
79
79
|
if association.nil?
|
@@ -8,9 +8,11 @@ module ActiveFedora
|
|
8
8
|
|
9
9
|
# Returns only the attached_files that are declared with 'contains'
|
10
10
|
def declared_attached_files
|
11
|
-
|
12
|
-
|
11
|
+
result = {}
|
12
|
+
attached_files.reflections.keys.each do |k|
|
13
|
+
result[k] = attached_files[k]
|
13
14
|
end
|
15
|
+
result
|
14
16
|
end
|
15
17
|
|
16
18
|
#
|
@@ -30,7 +32,7 @@ module ActiveFedora
|
|
30
32
|
end
|
31
33
|
|
32
34
|
def contains_assertions
|
33
|
-
resource.query(subject: resource, predicate: ::RDF::Vocab::LDP.contains).objects.map(&:to_s)
|
35
|
+
resource.query({ subject: resource, predicate: ::RDF::Vocab::LDP.contains }).objects.map(&:to_s)
|
34
36
|
end
|
35
37
|
|
36
38
|
# Load any undeclared relationships or has_subresource relationships. These are non-idiomatic LDP
|
@@ -29,10 +29,8 @@ module ActiveFedora
|
|
29
29
|
# cat.name # => 'Gorby'
|
30
30
|
# cat.status => 'sleeping'
|
31
31
|
def assign_attributes(new_attributes)
|
32
|
-
unless new_attributes.respond_to?(:stringify_keys)
|
33
|
-
|
34
|
-
end
|
35
|
-
return if new_attributes.nil? || new_attributes.empty?
|
32
|
+
raise ArgumentError, "When assigning attributes, you must pass a hash as an argument." unless new_attributes.respond_to?(:stringify_keys)
|
33
|
+
return if new_attributes.blank?
|
36
34
|
|
37
35
|
attributes = new_attributes.stringify_keys
|
38
36
|
_assign_attributes(sanitize_for_mass_assignment(attributes))
|
@@ -4,7 +4,7 @@ module ActiveFedora
|
|
4
4
|
module ClassMethods
|
5
5
|
protected
|
6
6
|
|
7
|
-
def define_method_attribute(name, owner: nil)
|
7
|
+
def define_method_attribute(name, owner: nil) # rubocop:disable Lint/UnusedMethodArgument
|
8
8
|
name = name.to_s
|
9
9
|
safe_name = name.unpack('h*'.freeze).first
|
10
10
|
temp_method = "__temp__#{safe_name}"
|
@@ -4,7 +4,7 @@ module ActiveFedora
|
|
4
4
|
module ClassMethods
|
5
5
|
protected
|
6
6
|
|
7
|
-
def define_method_attribute=(name, owner: nil)
|
7
|
+
def define_method_attribute=(name, owner: nil) # rubocop:disable Lint/UnusedMethodArgument
|
8
8
|
name = name.to_s
|
9
9
|
safe_name = name.unpack('h*'.freeze).first
|
10
10
|
ActiveFedora::AttributeMethods::AttrNames.set_name_cache safe_name, name
|
@@ -27,11 +27,9 @@ module ActiveFedora
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def write_attribute(attribute_name, value)
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
raise ActiveModel::MissingAttributeError, "can't write unknown attribute `#{attribute_name}'"
|
34
|
-
end
|
30
|
+
raise ActiveModel::MissingAttributeError, "can't write unknown attribute `#{attribute_name}'" unless self.class.properties.key?(attribute_name)
|
31
|
+
|
32
|
+
attributes[attribute_name] = value
|
35
33
|
end
|
36
34
|
|
37
35
|
private
|
@@ -13,12 +13,12 @@ module ActiveFedora
|
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
-
BLACKLISTED_CLASS_METHODS = %w
|
16
|
+
BLACKLISTED_CLASS_METHODS = %w[private public protected allocate new name parent superclass].freeze
|
17
17
|
|
18
18
|
class GeneratedAttributeMethods < Module; end # :nodoc:
|
19
19
|
|
20
20
|
module ClassMethods
|
21
|
-
def inherited(child_class)
|
21
|
+
def inherited(child_class) # :nodoc:
|
22
22
|
child_class.initialize_generated_modules
|
23
23
|
super
|
24
24
|
end
|
@@ -46,9 +46,7 @@ module ActiveFedora
|
|
46
46
|
# Person.instance_method_already_implemented?(:name)
|
47
47
|
# # => false
|
48
48
|
def instance_method_already_implemented?(method_name)
|
49
|
-
if dangerous_attribute_method?(method_name)
|
50
|
-
raise DangerousAttributeError, "#{method_name} is defined by Active Fedora. Check to make sure that you don't have an attribute or method with the same name."
|
51
|
-
end
|
49
|
+
raise DangerousAttributeError, "#{method_name} is defined by Active Fedora. Check to make sure that you don't have an attribute or method with the same name." if dangerous_attribute_method?(method_name)
|
52
50
|
|
53
51
|
if superclass == Base
|
54
52
|
super
|
@@ -148,9 +146,11 @@ module ActiveFedora
|
|
148
146
|
# person.attributes
|
149
147
|
# # => {"id"=>3, "created_at"=>Sun, 21 Oct 2012 04:53:04, "updated_at"=>Sun, 21 Oct 2012 04:53:04, "name"=>"Francesco", "age"=>22}
|
150
148
|
def attributes
|
151
|
-
|
152
|
-
|
149
|
+
result = {}
|
150
|
+
attribute_names.each do |name|
|
151
|
+
result[name] = read_attribute(name)
|
153
152
|
end
|
153
|
+
result
|
154
154
|
end
|
155
155
|
|
156
156
|
# Returns an <tt>#inspect</tt>-like string for the value of the
|
@@ -77,7 +77,7 @@ module ActiveFedora
|
|
77
77
|
# override activemodel so it doesn't trigger a load of all the attributes.
|
78
78
|
# the callback methods seem to trigger this, which means just initing an object (after_init)
|
79
79
|
# causes a load of all the datastreams.
|
80
|
-
def attribute_method?(attr_name)
|
80
|
+
def attribute_method?(attr_name) # :nodoc:
|
81
81
|
respond_to_without_attributes?(:attributes) && self.class.delegated_attributes.include?(attr_name)
|
82
82
|
end
|
83
83
|
|
@@ -77,7 +77,7 @@ module ActiveFedora
|
|
77
77
|
|
78
78
|
ASSOCIATION_TYPES = [:has_many, :belongs_to, :has_and_belongs_to_many, :directly_contains, :indirectly_contains, :is_a_container].freeze
|
79
79
|
|
80
|
-
module AssociationBuilderExtension
|
80
|
+
module AssociationBuilderExtension # :nodoc:
|
81
81
|
def self.valid_options
|
82
82
|
[:autosave]
|
83
83
|
end
|
@@ -199,7 +199,7 @@ module ActiveFedora
|
|
199
199
|
# unless the parent is/was a new record itself.
|
200
200
|
def associated_records_to_validate_or_save(association, new_record, autosave)
|
201
201
|
if new_record
|
202
|
-
association
|
202
|
+
association&.target
|
203
203
|
elsif autosave
|
204
204
|
association.target.find_all(&:changed_for_autosave?)
|
205
205
|
else
|
@@ -220,7 +220,7 @@ module ActiveFedora
|
|
220
220
|
# turned on for the association.
|
221
221
|
def validate_single_association(reflection)
|
222
222
|
association = association_instance_get(reflection.name)
|
223
|
-
record = association
|
223
|
+
record = association&.target
|
224
224
|
association_valid?(reflection, record) if record
|
225
225
|
end
|
226
226
|
|
@@ -306,7 +306,7 @@ module ActiveFedora
|
|
306
306
|
# In addition, it will destroy the association if it was marked for destruction.
|
307
307
|
def save_belongs_to_association(reflection)
|
308
308
|
association = association_instance_get(reflection.name)
|
309
|
-
record = association
|
309
|
+
record = association&.load_target
|
310
310
|
if record && !record.destroyed?
|
311
311
|
autosave = reflection.options[:autosave]
|
312
312
|
|
@@ -227,7 +227,7 @@ module ActiveFedora
|
|
227
227
|
define_model_callbacks :save, :create, :update, :destroy, :update_index
|
228
228
|
end
|
229
229
|
|
230
|
-
def destroy(*)
|
230
|
+
def destroy(*) # :nodoc:
|
231
231
|
_run_destroy_callbacks { super }
|
232
232
|
end
|
233
233
|
|
@@ -241,11 +241,11 @@ module ActiveFedora
|
|
241
241
|
_run_save_callbacks { super }
|
242
242
|
end
|
243
243
|
|
244
|
-
def _create_record(*)
|
244
|
+
def _create_record(*) # :nodoc:
|
245
245
|
_run_create_callbacks { super }
|
246
246
|
end
|
247
247
|
|
248
|
-
def _update_record(*)
|
248
|
+
def _update_record(*) # :nodoc:
|
249
249
|
_run_update_callbacks { super }
|
250
250
|
end
|
251
251
|
end
|
@@ -20,10 +20,10 @@ module ActiveFedora
|
|
20
20
|
if object.association(key.to_sym).present?
|
21
21
|
# This is always an ActiveFedora::Reflection::RDFPropertyReflection
|
22
22
|
predicate = object.association(key.to_sym).reflection.predicate
|
23
|
-
result[predicate] = graph.query(subject: object.rdf_subject, predicate: predicate)
|
23
|
+
result[predicate] = graph.query({ subject: object.rdf_subject, predicate: predicate })
|
24
24
|
elsif object.class.properties.keys.include?(key)
|
25
25
|
predicate = graph.reflections.reflect_on_property(key).predicate
|
26
|
-
results = graph.query(subject: object.rdf_subject, predicate: predicate)
|
26
|
+
results = graph.query({ subject: object.rdf_subject, predicate: predicate })
|
27
27
|
new_graph = child_graphs(results.map(&:object))
|
28
28
|
results.each do |res|
|
29
29
|
new_graph << res
|
@@ -32,7 +32,7 @@ module ActiveFedora
|
|
32
32
|
elsif key == 'type'.freeze
|
33
33
|
# working around https://github.com/ActiveTriples/ActiveTriples/issues/122
|
34
34
|
predicate = ::RDF.type
|
35
|
-
result[predicate] = graph.query(subject: object.rdf_subject, predicate: predicate)
|
35
|
+
result[predicate] = graph.query({ subject: object.rdf_subject, predicate: predicate })
|
36
36
|
elsif object.local_attributes.include?(key)
|
37
37
|
raise "Unable to find a graph predicate corresponding to the attribute: \"#{key}\""
|
38
38
|
end
|
@@ -46,11 +46,9 @@ module ActiveFedora
|
|
46
46
|
def child_graphs(objects)
|
47
47
|
child_graphs = ::RDF::Graph.new
|
48
48
|
objects.each do |object|
|
49
|
-
graph.query(subject: object).each do |statement|
|
49
|
+
graph.query({ subject: object }).each do |statement|
|
50
50
|
# Have to filter out Fedora triples.
|
51
|
-
unless FedoraStatement.new(statement).internal?
|
52
|
-
child_graphs << statement
|
53
|
-
end
|
51
|
+
child_graphs << statement unless FedoraStatement.new(statement).internal?
|
54
52
|
end
|
55
53
|
end
|
56
54
|
child_graphs
|
@@ -4,9 +4,7 @@ module ActiveFedora::Core
|
|
4
4
|
def self.call(id)
|
5
5
|
id = URI::DEFAULT_PARSER.escape(id, '[]'.freeze)
|
6
6
|
id = "/#{id}" unless id.start_with? SLASH
|
7
|
-
unless ActiveFedora.fedora.base_path == SLASH || id.start_with?("#{ActiveFedora.fedora.base_path}/")
|
8
|
-
id = ActiveFedora.fedora.base_path + id
|
9
|
-
end
|
7
|
+
id = ActiveFedora.fedora.base_path + id unless ActiveFedora.fedora.base_path == SLASH || id.start_with?("#{ActiveFedora.fedora.base_path}/")
|
10
8
|
ActiveFedora.fedora.host + id
|
11
9
|
end
|
12
10
|
end
|