active-fedora 9.9.0 → 9.10.0
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/.rubocop.yml +20 -6
- data/.travis.yml +2 -6
- data/History.txt +146 -0
- data/active-fedora.gemspec +11 -8
- data/lib/active_fedora/associations/association.rb +44 -14
- data/lib/active_fedora/associations/association_scope.rb +6 -2
- data/lib/active_fedora/associations/basic_contains_association.rb +2 -3
- data/lib/active_fedora/associations/belongs_to_association.rb +23 -14
- data/lib/active_fedora/associations/builder/association.rb +95 -41
- data/lib/active_fedora/associations/builder/belongs_to.rb +30 -2
- data/lib/active_fedora/associations/builder/collection_association.rb +36 -4
- data/lib/active_fedora/associations/builder/contains.rb +10 -5
- data/lib/active_fedora/associations/builder/directly_contains.rb +6 -8
- data/lib/active_fedora/associations/builder/directly_contains_one.rb +27 -20
- data/lib/active_fedora/associations/builder/has_and_belongs_to_many.rb +7 -3
- data/lib/active_fedora/associations/builder/has_many.rb +8 -45
- data/lib/active_fedora/associations/builder/indirectly_contains.rb +6 -8
- data/lib/active_fedora/associations/builder/property.rb +6 -12
- data/lib/active_fedora/associations/builder/singular_association.rb +3 -5
- data/lib/active_fedora/associations/builder/singular_property.rb +5 -4
- data/lib/active_fedora/associations/collection_association.rb +22 -26
- data/lib/active_fedora/associations/collection_proxy.rb +1 -1
- data/lib/active_fedora/associations/contained_finder.rb +1 -2
- data/lib/active_fedora/associations/directly_contains_one_association.rb +2 -3
- data/lib/active_fedora/associations/has_and_belongs_to_many_association.rb +1 -1
- data/lib/active_fedora/associations/has_many_association.rb +24 -5
- data/lib/active_fedora/associations/rdf.rb +1 -20
- data/lib/active_fedora/associations.rb +1 -1
- data/lib/active_fedora/attached_files.rb +2 -2
- data/lib/active_fedora/attribute_assignment.rb +55 -0
- data/lib/active_fedora/attribute_methods/read.rb +29 -44
- data/lib/active_fedora/attribute_methods/write.rb +16 -19
- data/lib/active_fedora/attribute_methods.rb +149 -29
- data/lib/active_fedora/attributes.rb +6 -18
- data/lib/active_fedora/autosave_association.rb +8 -12
- data/lib/active_fedora/base.rb +2 -2
- data/lib/active_fedora/caching_connection.rb +1 -1
- data/lib/active_fedora/callbacks.rb +9 -9
- data/lib/active_fedora/common.rb +67 -0
- data/lib/active_fedora/core.rb +11 -23
- data/lib/active_fedora/default_model_mapper.rb +24 -0
- data/lib/active_fedora/errors.rb +42 -0
- data/lib/active_fedora/fedora.rb +1 -1
- data/lib/active_fedora/file/attributes.rb +9 -10
- data/lib/active_fedora/file.rb +19 -56
- data/lib/active_fedora/file_persistence.rb +27 -0
- data/lib/active_fedora/indexing.rb +15 -9
- data/lib/active_fedora/indexing_service.rb +4 -4
- data/lib/active_fedora/inheritance.rb +34 -0
- data/lib/active_fedora/ldp_resource.rb +1 -0
- data/lib/active_fedora/model.rb +18 -16
- data/lib/active_fedora/model_classifier.rb +77 -0
- data/lib/active_fedora/nested_attributes.rb +145 -18
- data/lib/active_fedora/persistence.rb +23 -5
- data/lib/active_fedora/predicates.rb +3 -0
- data/lib/active_fedora/qualified_dublin_core_datastream.rb +1 -1
- data/lib/active_fedora/query_result_builder.rb +12 -28
- data/lib/active_fedora/querying.rb +1 -1
- data/lib/active_fedora/rdf/datastream_indexing.rb +1 -1
- data/lib/active_fedora/reflection.rb +212 -80
- data/lib/active_fedora/relation/calculations.rb +1 -5
- data/lib/active_fedora/relation/finder_methods.rb +39 -26
- data/lib/active_fedora/relation.rb +17 -0
- data/lib/active_fedora/scoping/default.rb +117 -0
- data/lib/active_fedora/scoping/named.rb +152 -4
- data/lib/active_fedora/scoping.rb +85 -2
- data/lib/active_fedora/simple_datastream.rb +1 -1
- data/lib/active_fedora/solr_hit.rb +71 -0
- data/lib/active_fedora/solr_instance_loader.rb +12 -36
- data/lib/active_fedora/solr_query_builder.rb +20 -25
- data/lib/active_fedora/solr_service.rb +24 -13
- data/lib/active_fedora/type/boolean.rb +23 -0
- data/lib/active_fedora/type/value.rb +118 -0
- data/lib/active_fedora/type.rb +8 -0
- data/lib/active_fedora/validations.rb +14 -5
- data/lib/active_fedora/version.rb +1 -1
- data/lib/active_fedora/versionable.rb +8 -7
- data/lib/active_fedora/with_metadata/metadata_node.rb +2 -1
- data/lib/active_fedora.rb +35 -15
- data/lib/generators/active_fedora/config/fedora/fedora_generator.rb +4 -0
- data/lib/generators/active_fedora/config/fedora/templates/.fcrepo_wrapper +3 -0
- data/lib/generators/active_fedora/config/solr/solr_generator.rb +4 -0
- data/lib/generators/active_fedora/config/solr/templates/.solr_wrapper +5 -0
- data/lib/generators/active_fedora/config/solr/templates/solr/config/solrconfig.xml +15 -0
- data/solr/config/solrconfig.xml +15 -0
- data/spec/config_helper.rb +0 -5
- data/spec/integration/associations_spec.rb +5 -5
- data/spec/integration/attached_files_spec.rb +4 -4
- data/spec/integration/base_spec.rb +4 -4
- data/spec/integration/bug_spec.rb +0 -1
- data/spec/integration/collection_association_spec.rb +34 -3
- data/spec/integration/file_spec.rb +2 -2
- data/spec/integration/full_featured_model_spec.rb +4 -4
- data/spec/integration/has_and_belongs_to_many_associations_spec.rb +1 -1
- data/spec/integration/has_many_associations_spec.rb +30 -1
- data/spec/integration/indirect_container_spec.rb +1 -1
- data/spec/integration/nested_attribute_spec.rb +6 -0
- data/spec/integration/ntriples_datastream_spec.rb +4 -4
- data/spec/integration/om_datastream_spec.rb +7 -7
- data/spec/integration/persistence_spec.rb +1 -1
- data/spec/integration/relation_delegation_spec.rb +1 -1
- data/spec/integration/scoped_query_spec.rb +13 -13
- data/spec/integration/solr_hit_spec.rb +52 -0
- data/spec/samples/hydra-mods_article_datastream.rb +2 -2
- data/spec/spec_helper.rb +5 -9
- data/spec/unit/active_fedora_spec.rb +0 -26
- data/spec/unit/attributes_spec.rb +13 -7
- data/spec/unit/base_spec.rb +20 -0
- data/spec/unit/builder/has_and_belongs_to_many_spec.rb +2 -3
- data/spec/unit/callback_spec.rb +3 -8
- data/spec/unit/collection_proxy_spec.rb +1 -1
- data/spec/unit/default_model_mapper_spec.rb +39 -0
- data/spec/unit/file_spec.rb +21 -2
- data/spec/unit/finder_methods_spec.rb +30 -6
- data/spec/unit/has_and_belongs_to_many_association_spec.rb +4 -4
- data/spec/unit/has_many_association_spec.rb +25 -3
- data/spec/unit/indexing_spec.rb +17 -3
- data/spec/unit/model_classifier_spec.rb +49 -0
- data/spec/unit/model_spec.rb +0 -9
- data/spec/unit/ntriples_datastream_spec.rb +16 -16
- data/spec/unit/om_datastream_spec.rb +7 -7
- data/spec/unit/qualified_dublin_core_datastream_spec.rb +1 -1
- data/spec/unit/query_result_builder_spec.rb +4 -10
- data/spec/unit/query_spec.rb +28 -28
- data/spec/unit/rdf/indexing_service_spec.rb +16 -16
- data/spec/unit/reflection_spec.rb +2 -2
- data/spec/unit/scoping_spec.rb +67 -0
- data/spec/unit/simple_datastream_spec.rb +2 -2
- data/spec/unit/solr_config_options_spec.rb +29 -32
- data/spec/unit/solr_hit_spec.rb +58 -0
- data/spec/unit/solr_query_builder_spec.rb +9 -1
- data/spec/unit/solr_service_spec.rb +19 -3
- data/spec/unit/validations_spec.rb +1 -1
- metadata +82 -20
- data/spec/support/freeze_mocks.rb +0 -12
|
@@ -1,57 +1,104 @@
|
|
|
1
1
|
module ActiveFedora::Associations::Builder
|
|
2
2
|
class Association #:nodoc:
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
class_attribute :macro
|
|
3
|
+
class << self
|
|
4
|
+
attr_accessor :extensions
|
|
5
|
+
end
|
|
6
|
+
self.extensions = []
|
|
8
7
|
|
|
9
|
-
|
|
8
|
+
VALID_OPTIONS = [:class_name, :predicate, :type_validator].freeze
|
|
10
9
|
|
|
11
10
|
# configure_dependency
|
|
12
|
-
def self.build(model, name, options)
|
|
13
|
-
|
|
11
|
+
def self.build(model, name, options, &block)
|
|
12
|
+
if model.dangerous_attribute_method?(name)
|
|
13
|
+
Deprecation.warn(ActiveFedora::Base, "You tried to define an association named #{name} on the model #{model.name}, but " \
|
|
14
|
+
"this will conflict with a method #{name} already defined by ActiveFedora. " \
|
|
15
|
+
"Please choose a different association name.")
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
extension = define_extensions model, name, &block
|
|
19
|
+
reflection = create_reflection model, name, nil, options, extension
|
|
14
20
|
define_accessors(model, reflection)
|
|
15
21
|
define_callbacks(model, reflection)
|
|
22
|
+
define_validations model, reflection
|
|
16
23
|
reflection
|
|
17
24
|
end
|
|
18
25
|
|
|
19
|
-
def
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
validate_options
|
|
26
|
+
def self.create_reflection(model, name, scope, options, extension = nil)
|
|
27
|
+
unless name.is_a?(Symbol)
|
|
28
|
+
name = name.to_sym
|
|
29
|
+
Deprecation.warn(ActiveFedora::Base, "association names must be a Symbol")
|
|
30
|
+
end
|
|
31
|
+
validate_options(options)
|
|
32
|
+
translate_property_to_predicate(options)
|
|
33
|
+
|
|
34
|
+
scope = build_scope(scope, extension)
|
|
35
|
+
name = better_name(name)
|
|
36
|
+
|
|
37
|
+
ActiveFedora::Reflection.create(macro, name, scope, options, model)
|
|
25
38
|
end
|
|
26
39
|
|
|
27
|
-
def
|
|
28
|
-
|
|
29
|
-
|
|
40
|
+
def self.build_scope(scope, extension)
|
|
41
|
+
new_scope = scope
|
|
42
|
+
|
|
43
|
+
new_scope = proc { instance_exec(&scope) } if scope && scope.arity == 0
|
|
44
|
+
|
|
45
|
+
new_scope = wrap_scope new_scope, extension if extension
|
|
46
|
+
|
|
47
|
+
new_scope
|
|
30
48
|
end
|
|
31
49
|
|
|
32
|
-
def
|
|
50
|
+
def self.wrap_scope(scope, _extension)
|
|
51
|
+
scope
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def self.macro
|
|
55
|
+
raise NotImplementedError
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def self.valid_options(_options)
|
|
59
|
+
VALID_OPTIONS + Association.extensions.flat_map(&:valid_options)
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def self.validate_options(options)
|
|
63
|
+
options.assert_valid_keys(valid_options(options))
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def self.better_name(name)
|
|
67
|
+
name
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def self.translate_property_to_predicate(options)
|
|
33
71
|
return unless options[:property]
|
|
34
72
|
Deprecation.warn Association, "the :property option to `#{model}.#{macro} :#{name}' is deprecated and will be removed in active-fedora 10.0. Use :predicate instead", caller(5)
|
|
35
73
|
options[:predicate] = predicate(options.delete(:property))
|
|
36
74
|
end
|
|
37
75
|
|
|
38
|
-
def validate_options
|
|
39
|
-
options.assert_valid_keys(self.class.valid_options)
|
|
40
|
-
end
|
|
41
|
-
|
|
42
76
|
# Returns the RDF predicate as defined by the :property attribute
|
|
43
|
-
def predicate(property)
|
|
77
|
+
def self.predicate(property)
|
|
44
78
|
return property if property.is_a? RDF::URI
|
|
45
79
|
ActiveFedora::Predicates.find_graph_predicate(property)
|
|
46
80
|
end
|
|
47
81
|
|
|
82
|
+
def self.define_extensions(_model, _name)
|
|
83
|
+
end
|
|
84
|
+
|
|
48
85
|
def self.define_callbacks(model, reflection)
|
|
49
86
|
if dependent = reflection.options[:dependent]
|
|
50
87
|
check_dependent_options(dependent)
|
|
51
88
|
add_destroy_callbacks(model, reflection)
|
|
52
89
|
end
|
|
90
|
+
|
|
91
|
+
Association.extensions.each do |extension|
|
|
92
|
+
extension.build model, reflection
|
|
93
|
+
end
|
|
53
94
|
end
|
|
54
95
|
|
|
96
|
+
# Defines the setter and getter methods for the association
|
|
97
|
+
# class Post < ActiveRecord::Base
|
|
98
|
+
# has_many :comments
|
|
99
|
+
# end
|
|
100
|
+
#
|
|
101
|
+
# Post.first.comments and Post.first.comments= methods are defined by this method...
|
|
55
102
|
def self.define_accessors(model, reflection)
|
|
56
103
|
mixin = model.generated_association_methods
|
|
57
104
|
name = reflection.name
|
|
@@ -60,31 +107,38 @@ module ActiveFedora::Associations::Builder
|
|
|
60
107
|
end
|
|
61
108
|
|
|
62
109
|
def self.define_readers(mixin, name)
|
|
63
|
-
mixin.
|
|
64
|
-
|
|
65
|
-
|
|
110
|
+
mixin.class_eval <<-CODE, __FILE__, __LINE__ + 1
|
|
111
|
+
def #{name}(*args)
|
|
112
|
+
association(:#{name}).reader(*args)
|
|
113
|
+
end
|
|
114
|
+
CODE
|
|
66
115
|
end
|
|
67
116
|
|
|
68
117
|
def self.define_writers(mixin, name)
|
|
69
|
-
mixin.
|
|
70
|
-
|
|
71
|
-
|
|
118
|
+
mixin.class_eval <<-CODE, __FILE__, __LINE__ + 1
|
|
119
|
+
def #{name}=(value)
|
|
120
|
+
association(:#{name}).writer(value)
|
|
121
|
+
end
|
|
122
|
+
CODE
|
|
72
123
|
end
|
|
73
124
|
|
|
74
|
-
def
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
125
|
+
def self.define_validations(_model, _reflection)
|
|
126
|
+
# noop
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
def self.valid_dependent_options
|
|
130
|
+
raise NotImplementedError
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
def self.check_dependent_options(dependent)
|
|
134
|
+
unless valid_dependent_options.include? dependent
|
|
135
|
+
raise ArgumentError, "The :dependent option must be one of #{valid_dependent_options}, but is :#{dependent}"
|
|
78
136
|
end
|
|
137
|
+
end
|
|
79
138
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
association = #{name}
|
|
84
|
-
association.#{options[:dependent]} if association
|
|
85
|
-
end
|
|
86
|
-
eoruby
|
|
87
|
-
model.after_destroy method_name
|
|
139
|
+
def self.add_destroy_callbacks(model, reflection)
|
|
140
|
+
name = reflection.name
|
|
141
|
+
model.before_destroy ->(o) { o.association(name).handle_dependency }
|
|
88
142
|
end
|
|
89
143
|
end
|
|
90
144
|
end
|
|
@@ -1,11 +1,39 @@
|
|
|
1
1
|
module ActiveFedora::Associations::Builder
|
|
2
2
|
class BelongsTo < SingularAssociation #:nodoc:
|
|
3
|
-
self.macro
|
|
3
|
+
def self.macro
|
|
4
|
+
:belongs_to
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def self.valid_options(options)
|
|
8
|
+
super + [:optional]
|
|
9
|
+
end
|
|
4
10
|
|
|
5
|
-
def
|
|
11
|
+
def self.valid_dependent_options
|
|
12
|
+
[:destroy, :delete]
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def self.validate_options(options)
|
|
6
16
|
super
|
|
7
17
|
raise "You must specify a predicate for #{name}" unless options[:predicate]
|
|
8
18
|
raise ArgumentError, "Predicate must be a kind of RDF::URI" unless options[:predicate].is_a?(RDF::URI)
|
|
9
19
|
end
|
|
20
|
+
|
|
21
|
+
def self.define_validations(model, reflection)
|
|
22
|
+
if reflection.options.key?(:required)
|
|
23
|
+
reflection.options[:optional] = !reflection.options.delete(:required)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
required = if reflection.options[:optional].nil?
|
|
27
|
+
model.belongs_to_required_by_default
|
|
28
|
+
else
|
|
29
|
+
!reflection.options[:optional]
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
super
|
|
33
|
+
|
|
34
|
+
if required
|
|
35
|
+
model.validates_presence_of reflection.name, message: :required
|
|
36
|
+
end
|
|
37
|
+
end
|
|
10
38
|
end
|
|
11
39
|
end
|
|
@@ -3,22 +3,54 @@ module ActiveFedora::Associations::Builder
|
|
|
3
3
|
class CollectionAssociation < Association #:nodoc:
|
|
4
4
|
CALLBACKS = [:before_add, :after_add, :before_remove, :after_remove].freeze
|
|
5
5
|
|
|
6
|
-
self.valid_options
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
def self.valid_options(options)
|
|
7
|
+
super + CALLBACKS
|
|
8
|
+
end
|
|
9
9
|
|
|
10
10
|
def self.define_callbacks(model, reflection)
|
|
11
|
+
super
|
|
11
12
|
name = reflection.name
|
|
12
13
|
options = reflection.options
|
|
13
14
|
CALLBACKS.each { |callback_name| define_callback(model, callback_name, name, options) }
|
|
14
15
|
end
|
|
15
16
|
|
|
17
|
+
def self.define_extensions(model, name)
|
|
18
|
+
if block_given?
|
|
19
|
+
extension_module_name = "#{model.name.demodulize}#{name.to_s.camelize}AssociationExtension"
|
|
20
|
+
extension = Module.new(&Proc.new)
|
|
21
|
+
model.parent.const_set(extension_module_name, extension)
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
16
25
|
def self.define_callback(model, callback_name, name, options)
|
|
17
26
|
full_callback_name = "#{callback_name}_for_#{name}"
|
|
18
27
|
|
|
19
28
|
# TODO : why do i need method_defined? I think its because of the inheritance chain
|
|
20
29
|
model.class_attribute full_callback_name.to_sym unless model.method_defined?(full_callback_name)
|
|
21
|
-
|
|
30
|
+
|
|
31
|
+
callbacks = Array(options[callback_name.to_sym]).map do |callback|
|
|
32
|
+
case callback
|
|
33
|
+
when Symbol
|
|
34
|
+
->(_method, owner, record) { owner.send(callback, record) }
|
|
35
|
+
when Proc
|
|
36
|
+
->(_method, owner, record) { callback.call(owner, record) }
|
|
37
|
+
else
|
|
38
|
+
->(method, owner, record) { callback.send(method, owner, record) }
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
model.send("#{full_callback_name}=", callbacks)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def self.wrap_scope(scope, mod)
|
|
45
|
+
if scope
|
|
46
|
+
if scope.arity > 0
|
|
47
|
+
proc { |owner| instance_exec(owner, &scope).extending(mod) }
|
|
48
|
+
else
|
|
49
|
+
proc { instance_exec(&scope).extending(mod) }
|
|
50
|
+
end
|
|
51
|
+
else
|
|
52
|
+
proc { extending(mod) }
|
|
53
|
+
end
|
|
22
54
|
end
|
|
23
55
|
end
|
|
24
56
|
end
|
|
@@ -1,14 +1,19 @@
|
|
|
1
1
|
module ActiveFedora::Associations::Builder
|
|
2
2
|
class Contains < SingularAssociation #:nodoc:
|
|
3
|
-
self.macro
|
|
4
|
-
|
|
3
|
+
def self.macro
|
|
4
|
+
:contains
|
|
5
|
+
end
|
|
5
6
|
|
|
6
|
-
def
|
|
7
|
-
super
|
|
7
|
+
def self.valid_options(options)
|
|
8
|
+
super + [:autocreate, :block]
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def self.create_reflection(model, name, scope, options, extension = nil)
|
|
8
12
|
options[:class_name] = 'ActiveFedora::File' if options[:class_name].blank?
|
|
13
|
+
super(model, name, scope, options, extension)
|
|
9
14
|
end
|
|
10
15
|
|
|
11
|
-
def validate_options
|
|
16
|
+
def self.validate_options(options)
|
|
12
17
|
super
|
|
13
18
|
return unless options[:class_name] && !options[:class_name].is_a?(String)
|
|
14
19
|
raise ArgumentError, ":class_name must be a string for contains '#{name}'"
|
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
module ActiveFedora::Associations::Builder
|
|
2
2
|
class DirectlyContains < CollectionAssociation #:nodoc:
|
|
3
|
-
self.macro
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
def self.macro
|
|
4
|
+
:directly_contains
|
|
5
|
+
end
|
|
6
6
|
|
|
7
|
-
def
|
|
8
|
-
|
|
9
|
-
configure_dependency
|
|
10
|
-
reflection
|
|
7
|
+
def self.valid_options(options)
|
|
8
|
+
super + [:has_member_relation, :is_member_of_relation] - [:predicate]
|
|
11
9
|
end
|
|
12
10
|
|
|
13
|
-
def validate_options
|
|
11
|
+
def self.validate_options(options)
|
|
14
12
|
super
|
|
15
13
|
if !options[:has_member_relation] && !options[:is_member_of_relation]
|
|
16
14
|
raise ArgumentError, "You must specify a :has_member_relation or :is_member_of_relation predicate for #{name}"
|
|
@@ -1,14 +1,25 @@
|
|
|
1
1
|
module ActiveFedora::Associations::Builder
|
|
2
2
|
class DirectlyContainsOne < SingularAssociation #:nodoc:
|
|
3
|
-
self.macro
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
def self.macro
|
|
4
|
+
:directly_contains_one
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def self.valid_options(options)
|
|
8
|
+
super + [:has_member_relation, :is_member_of_relation, :type, :through] - [:predicate]
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def self.create_reflection(model, name, scope, options, extension = nil)
|
|
12
|
+
if options[:through]
|
|
13
|
+
inherit_options_from_association(model, options, options[:through])
|
|
14
|
+
else
|
|
15
|
+
raise ArgumentError, "you must specify a :through option on #{name}. #{name} will use the container from that directly_contains association."
|
|
16
|
+
end
|
|
6
17
|
|
|
7
|
-
def validate_options
|
|
8
|
-
raise ArgumentError, "you must specify a :through option on #{name}. #{name} will use the container from that directly_contains association." unless options[:through]
|
|
9
|
-
inherit_options_from_association(options[:through]) if options[:through]
|
|
10
18
|
super
|
|
19
|
+
end
|
|
11
20
|
|
|
21
|
+
def self.validate_options(options)
|
|
22
|
+
super
|
|
12
23
|
if options[:class_name] == "ActiveFedora::File"
|
|
13
24
|
raise ArgumentError, "You cannot set :class_name of #{name} to ActiveFedora::File because directly_contains_one needs to assert and read RDF.type assertions, which is not supported by ActiveFedora::File. To make Files support RDF.type assertions, define a subclass of ActiveFedora::File and make it `include ActiveFedora::WithMetadata`. Otherwise, all subclasses of ActiveFedora::Base support RDF.type assertions."
|
|
14
25
|
elsif !options[:has_member_relation] && !options[:is_member_of_relation]
|
|
@@ -21,20 +32,16 @@ module ActiveFedora::Associations::Builder
|
|
|
21
32
|
raise ArgumentError, "You must specify a Type and it must be a kind of RDF::URI"
|
|
22
33
|
end
|
|
23
34
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
options[:class_name] = associated_through_reflection.options[:class_name] unless options[:class_name] && options[:class_name] != "ActiveFedora::File"
|
|
34
|
-
end
|
|
35
|
+
# Inherits :has_member_relation from the association corresponding to association_name
|
|
36
|
+
# @param [Symbol] association_name of the association to inherit from
|
|
37
|
+
def self.inherit_options_from_association(model, options, association_name)
|
|
38
|
+
associated_through_reflection = model._reflect_on_association(association_name)
|
|
39
|
+
raise ArgumentError, "You specified `:through => #{@reflection.options[:through]}` on the #{name} associaiton but #{model} does not actually have a #{@reflection.options[:through]}` association" if associated_through_reflection.nil? || !associated_through_reflection.name
|
|
40
|
+
raise ArgumentError, "You must specify a directly_contains association as the :through option on #{name}. You provided a #{associated_through_reflection.macro}" unless associated_through_reflection.macro == :directly_contains
|
|
41
|
+
options[:has_member_relation] = associated_through_reflection.options[:has_member_relation] unless options[:has_member_relation]
|
|
42
|
+
options[:class_name] = associated_through_reflection.options[:class_name] unless options[:class_name] && options[:class_name] != "ActiveFedora::File"
|
|
43
|
+
end
|
|
35
44
|
|
|
36
|
-
|
|
37
|
-
model.reflect_on_association(association_name)
|
|
38
|
-
end
|
|
45
|
+
private_class_method :inherit_options_from_association
|
|
39
46
|
end
|
|
40
47
|
end
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
module ActiveFedora::Associations::Builder
|
|
2
2
|
class HasAndBelongsToMany < CollectionAssociation #:nodoc:
|
|
3
3
|
extend Deprecation
|
|
4
|
-
self.macro
|
|
4
|
+
def self.macro
|
|
5
|
+
:has_and_belongs_to_many
|
|
6
|
+
end
|
|
5
7
|
|
|
6
|
-
self.valid_options
|
|
8
|
+
def self.valid_options(options)
|
|
9
|
+
super + [:inverse_of, :solr_page_size]
|
|
10
|
+
end
|
|
7
11
|
|
|
8
|
-
def validate_options
|
|
12
|
+
def self.validate_options(options)
|
|
9
13
|
super
|
|
10
14
|
Deprecation.warn HasAndBelongsToMany, ":solr_page_size doesn't do anything anymore and will be removed in ActiveFedora 10" if options.key?(:solr_page_size)
|
|
11
15
|
raise "You must specify a predicate for #{name}" unless options[:predicate]
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
module ActiveFedora::Associations::Builder
|
|
2
2
|
class HasMany < CollectionAssociation #:nodoc:
|
|
3
|
-
self.macro
|
|
3
|
+
def self.macro
|
|
4
|
+
:has_many
|
|
5
|
+
end
|
|
4
6
|
|
|
5
|
-
self.valid_options
|
|
7
|
+
def self.valid_options(options)
|
|
8
|
+
super + [:as, :dependent, :inverse_of]
|
|
9
|
+
end
|
|
6
10
|
|
|
7
|
-
def
|
|
8
|
-
|
|
9
|
-
configure_dependency
|
|
10
|
-
reflection
|
|
11
|
+
def self.valid_dependent_options
|
|
12
|
+
[:destroy, :delete_all, :nullify, :restrict_with_error, :restrict_with_exception]
|
|
11
13
|
end
|
|
12
14
|
|
|
13
15
|
def self.define_readers(mixin, name)
|
|
@@ -25,44 +27,5 @@ module ActiveFedora::Associations::Builder
|
|
|
25
27
|
association(name).ids_writer(ids)
|
|
26
28
|
end
|
|
27
29
|
end
|
|
28
|
-
|
|
29
|
-
private
|
|
30
|
-
|
|
31
|
-
def configure_dependency
|
|
32
|
-
return unless options[:dependent]
|
|
33
|
-
unless [:destroy, :delete_all, :nullify, :restrict].include?(options[:dependent])
|
|
34
|
-
raise ArgumentError, "The :dependent option expects either :destroy, :delete_all, " \
|
|
35
|
-
":nullify or :restrict (#{options[:dependent].inspect})"
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
send("define_#{options[:dependent]}_dependency_method")
|
|
39
|
-
model.before_destroy dependency_method_name
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
def define_destroy_dependency_method
|
|
43
|
-
name = self.name
|
|
44
|
-
model.send(:define_method, dependency_method_name) do
|
|
45
|
-
send(name).delete_all
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
def define_delete_all_dependency_method
|
|
50
|
-
name = self.name
|
|
51
|
-
model.send(:define_method, dependency_method_name) do
|
|
52
|
-
send(name).delete_all
|
|
53
|
-
end
|
|
54
|
-
end
|
|
55
|
-
alias define_nullify_dependency_method define_delete_all_dependency_method
|
|
56
|
-
|
|
57
|
-
def define_restrict_dependency_method
|
|
58
|
-
name = self.name
|
|
59
|
-
model.send(:define_method, dependency_method_name) do
|
|
60
|
-
raise ActiveRecord::DeleteRestrictionError, name unless send(name).empty?
|
|
61
|
-
end
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
def dependency_method_name
|
|
65
|
-
"has_many_dependent_for_#{name}"
|
|
66
|
-
end
|
|
67
30
|
end
|
|
68
31
|
end
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
module ActiveFedora::Associations::Builder
|
|
2
2
|
class IndirectlyContains < CollectionAssociation #:nodoc:
|
|
3
|
-
self.macro
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
def self.macro
|
|
4
|
+
:indirectly_contains
|
|
5
|
+
end
|
|
6
6
|
|
|
7
|
-
def
|
|
8
|
-
|
|
9
|
-
configure_dependency
|
|
10
|
-
reflection
|
|
7
|
+
def self.valid_options(options)
|
|
8
|
+
super + [:has_member_relation, :is_member_of_relation, :inserted_content_relation, :foreign_key, :through] - [:predicate]
|
|
11
9
|
end
|
|
12
10
|
|
|
13
11
|
def self.define_readers(mixin, name)
|
|
@@ -18,7 +16,7 @@ module ActiveFedora::Associations::Builder
|
|
|
18
16
|
end
|
|
19
17
|
end
|
|
20
18
|
|
|
21
|
-
def validate_options
|
|
19
|
+
def self.validate_options(options)
|
|
22
20
|
super
|
|
23
21
|
if !options[:has_member_relation] && !options[:is_member_of_relation]
|
|
24
22
|
raise ArgumentError, "You must specify a predicate for #{name}"
|
|
@@ -1,21 +1,15 @@
|
|
|
1
1
|
module ActiveFedora::Associations::Builder
|
|
2
2
|
class Property < Association
|
|
3
|
-
self.macro
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
def initialize(model, name, options)
|
|
7
|
-
super
|
|
8
|
-
@name = :"#{name.to_s.singularize}_ids"
|
|
3
|
+
def self.macro
|
|
4
|
+
:rdf
|
|
9
5
|
end
|
|
10
6
|
|
|
11
|
-
def
|
|
12
|
-
super
|
|
13
|
-
model.index_config[name] = build_index_config(reflection)
|
|
14
|
-
end
|
|
7
|
+
def self.valid_options(options)
|
|
8
|
+
super
|
|
15
9
|
end
|
|
16
10
|
|
|
17
|
-
def
|
|
18
|
-
|
|
11
|
+
def self.better_name(name)
|
|
12
|
+
:"#{name.to_s.singularize}_ids"
|
|
19
13
|
end
|
|
20
14
|
end
|
|
21
15
|
end
|
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
module ActiveFedora::Associations::Builder
|
|
2
2
|
class SingularAssociation < Association #:nodoc:
|
|
3
|
-
self.valid_options
|
|
4
|
-
|
|
5
|
-
def self.constructable?
|
|
6
|
-
true
|
|
3
|
+
def self.valid_options(options)
|
|
4
|
+
super + [:dependent, :inverse_of, :required]
|
|
7
5
|
end
|
|
8
6
|
|
|
9
7
|
def self.define_accessors(model, reflection)
|
|
10
8
|
super
|
|
11
|
-
define_constructors(model.generated_association_methods, reflection.name) if constructable?
|
|
9
|
+
define_constructors(model.generated_association_methods, reflection.name) if reflection.constructable?
|
|
12
10
|
end
|
|
13
11
|
|
|
14
12
|
def self.define_constructors(mixin, name)
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
module ActiveFedora::Associations::Builder
|
|
2
2
|
class SingularProperty < Property
|
|
3
|
-
self.macro
|
|
3
|
+
def self.macro
|
|
4
|
+
:singular_rdf
|
|
5
|
+
end
|
|
4
6
|
|
|
5
|
-
def
|
|
6
|
-
|
|
7
|
-
@name = :"#{name}_id"
|
|
7
|
+
def self.better_name(name)
|
|
8
|
+
:"#{name}_id"
|
|
8
9
|
end
|
|
9
10
|
end
|
|
10
11
|
end
|