active-fedora 6.2.0 → 6.3.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/.mailmap +9 -0
- data/CONTRIBUTORS.md +25 -0
- data/History.txt +52 -0
- data/active-fedora.gemspec +1 -1
- data/config/jetty.yml +1 -1
- data/gemfiles/gemfile.rails4 +1 -1
- data/lib/active_fedora/associations.rb +16 -1
- data/lib/active_fedora/associations/association_collection.rb +20 -2
- data/lib/active_fedora/associations/has_and_belongs_to_many_association.rb +7 -0
- data/lib/active_fedora/base.rb +32 -8
- data/lib/active_fedora/datastream.rb +7 -0
- data/lib/active_fedora/datastreams.rb +1 -0
- data/lib/active_fedora/nested_attributes.rb +34 -9
- data/lib/active_fedora/reflection.rb +7 -25
- data/lib/active_fedora/solr_digital_object.rb +4 -0
- data/lib/active_fedora/solr_service.rb +12 -9
- data/lib/active_fedora/unsaved_digital_object.rb +3 -0
- data/lib/active_fedora/validations.rb +7 -0
- data/lib/active_fedora/version.rb +1 -1
- data/lib/tasks/active_fedora_dev.rake +2 -11
- data/spec/fixtures/mods_articles/{hydrangea_article1.xml → mods_article1.xml} +0 -0
- data/spec/fixtures/{hydrangea_fixture_mods_article1.foxml.xml → test_fixture_mods_article1.foxml.xml} +5 -5
- data/spec/fixtures/{hydrangea_fixture_mods_article2.foxml.xml → test_fixture_mods_article2.foxml.xml} +5 -5
- data/spec/integration/associations_spec.rb +116 -33
- data/spec/integration/base_spec.rb +13 -35
- data/spec/integration/datastream_collections_spec.rb +6 -5
- data/spec/integration/datastream_spec.rb +21 -18
- data/spec/integration/datastreams_spec.rb +1 -3
- data/spec/integration/model_spec.rb +6 -6
- data/spec/integration/mods_article_integration_spec.rb +2 -2
- data/spec/integration/nested_attribute_spec.rb +88 -10
- data/spec/integration/ntriples_datastream_spec.rb +1 -1
- data/spec/integration/om_datastream_spec.rb +22 -22
- data/spec/integration/solr_instance_loader_spec.rb +4 -4
- data/spec/integration/solr_service_spec.rb +1 -1
- data/spec/samples/models/{hydrangea_article.rb → mods_article.rb} +2 -2
- data/spec/samples/samples.rb +1 -1
- data/spec/unit/base_spec.rb +12 -12
- data/spec/unit/datastreams_spec.rb +0 -10
- data/spec/unit/has_and_belongs_to_many_collection_spec.rb +0 -27
- data/spec/unit/has_many_collection_spec.rb +0 -28
- data/spec/unit/om_datastream_spec.rb +6 -6
- data/spec/unit/query_spec.rb +2 -2
- data/spec/unit/solr_config_options_spec.rb +1 -1
- data/spec/unit/solr_service_spec.rb +9 -1
- data/spec/unit/validations_spec.rb +18 -11
- metadata +18 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bcded8e76a404beaf4995b0a8d4ff0f9747e5170
|
4
|
+
data.tar.gz: 449b9bb2fd96f88fc07e6fe6ab3aecc9015cfe5b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fc219dd3f66394ef8da3b7fca9aeef738f6de5bf91e51d8d8f51b0df35ea52e3f360d7c61477266399bf77bf7a06b9dd9ee196c1758363a5924e41d47756f1cf
|
7
|
+
data.tar.gz: fa2a07fc6796b488e542ab397333a47aff1ac6db3018b5355c654821407ae3f1a7b45493ec05be8cae67d0cb871d25a0e13bf4210b7764734b5965016734fbc1
|
data/.mailmap
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
Mark Bussey <mark@curationexperts.com> mark-dce <mark@curationexperts.com>
|
2
|
+
Andrew Myers <andrew_myers@wgbh.org> afred <afredmyers@gmail.com>
|
3
|
+
Richard Johnson <rick.johnson@nd.edu> rjohns14@github.com <rjohns14@LIB-1224.library.nd.edu>
|
4
|
+
Richard Johnson <rick.johnson@nd.edu> rjohns14 <rjohns14@LIB-1224.library.nd.edu>
|
5
|
+
Richard Johnson <rick.johnson@nd.edu> rickjohnson <rick.johnson@nd.edu>
|
6
|
+
Justin Coyne <justin@curationexperts.com> jcoyne <digger250@gmail.com>
|
7
|
+
Chris Colvard <cjcolvar@indiana.edu> cjcolvar <cjcolvar@indiana.edu>
|
8
|
+
David Chandek-Stark <dchandekstark@gmail.com> dchandekstark <dchandekstark@gmail.com>
|
9
|
+
Matt Zumwalt <matt.zumwalt@yourmediashelf.com> flyingzumwalt <matt.zumwalt@gmail.com>
|
data/CONTRIBUTORS.md
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
Contributors to this project:
|
2
|
+
|
3
|
+
* Adam Wead
|
4
|
+
* Andrew Curley
|
5
|
+
* Benjamin Armintor
|
6
|
+
* Bess Sadler
|
7
|
+
* Carolyn Cole
|
8
|
+
* Chris Beer
|
9
|
+
* Chris Colvard
|
10
|
+
* David Chandek-Stark
|
11
|
+
* Edwin Shin
|
12
|
+
* Jeremy Friesen
|
13
|
+
* Jessie Keck
|
14
|
+
* John Scofield
|
15
|
+
* Justin Coyne
|
16
|
+
* Matt Zumwalt
|
17
|
+
* Michael B. Klein
|
18
|
+
* Michael J. Giarlo
|
19
|
+
* Michael Klein
|
20
|
+
* Mirosław Boruta
|
21
|
+
* Naomi Dushay
|
22
|
+
* Richard Johnson
|
23
|
+
* Thomas Johnson
|
24
|
+
* mpc3c
|
25
|
+
|
data/History.txt
CHANGED
@@ -1,3 +1,55 @@
|
|
1
|
+
6.3.0 (2013-06-14)
|
2
|
+
|
3
|
+
Added method: ActiveFedora::Base#required? [Justin Coyne]
|
4
|
+
|
5
|
+
Removed redundant MacroReflection#klass method definition. Removed some excessive whitespace. [David Chandek-Stark]
|
6
|
+
|
7
|
+
Updated doc comment for .count to reflect change made in commit 1cd412a817f5d7b5c2f2cbc304b915b7423c499d. [David Chandek-Stark]
|
8
|
+
|
9
|
+
Adding CONTRIBUTORS and mailmap [Jeremy Friesen]
|
10
|
+
|
11
|
+
Test against rails 4.0.0.rc2 [Justin Coyne]
|
12
|
+
|
13
|
+
Backwards compatible change adding optional `args' param to ActiveFedora::SolrService.count, enabling the method to pass args through to ActiveFedora::SolrService.query. [David Chandek-Stark]
|
14
|
+
|
15
|
+
habtm#delete saves between the before and after hook. [Justin Coyne]
|
16
|
+
|
17
|
+
Added association delete callbacks [Justin Coyne]
|
18
|
+
|
19
|
+
Fix nested_attributes handling [Mirosław Boruta]
|
20
|
+
|
21
|
+
Startup wait in one spot [Justin Coyne]
|
22
|
+
|
23
|
+
Remove unnecessary environment task [Chris Colvard]
|
24
|
+
|
25
|
+
try to use a createdDate accessor on @inner_object if it is available [Chris Beer]
|
26
|
+
|
27
|
+
use our test namespace rather than minting a new one in base_spec [Chris Beer]
|
28
|
+
|
29
|
+
remove checks for fedora default values [Chris Beer]
|
30
|
+
|
31
|
+
remove unnecessary test [Chris Beer]
|
32
|
+
|
33
|
+
add support for rubydora's #uri method (for fcrepo4 compatbility) [Chris Beer]
|
34
|
+
|
35
|
+
wrap property accessors in multi -> single valued wrappers [Chris Beer]
|
36
|
+
|
37
|
+
Closes #84 [David Chandek-Stark]
|
38
|
+
|
39
|
+
Modify or remove tests that check for DC datastreams; deprecate Datastreams#dc in favor of Datastreams#datastreams["DC"] [Chris Colvard]
|
40
|
+
|
41
|
+
Using Rubydora's mint for assign_pid [Jeremy Friesen]
|
42
|
+
|
43
|
+
fix #87 - use solr's !raw and sub-query feature to handle solr query escaping [Chris Beer]
|
44
|
+
|
45
|
+
Reworking datastream id spec to be order agnostic [Jeremy Friesen]
|
46
|
+
|
47
|
+
fix #87 - use solr _query_ to encapsulate solr queries for escaping [Chris Beer]
|
48
|
+
|
49
|
+
Fix validations unit test to pass legitimately [Andrew Curley]
|
50
|
+
|
51
|
+
|
52
|
+
|
1
53
|
6.2.0 (2013-06-05)
|
2
54
|
|
3
55
|
Support for rails 4
|
data/active-fedora.gemspec
CHANGED
@@ -19,7 +19,7 @@ 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.6')
|
22
|
+
s.add_dependency("rubydora", '~>1.6', '>= 1.6.5')
|
23
23
|
s.add_dependency("rdf")
|
24
24
|
s.add_dependency("rdf-rdfxml", '~>1.0.0')
|
25
25
|
s.add_dependency("deprecation")
|
data/config/jetty.yml
CHANGED
data/gemfiles/gemfile.rails4
CHANGED
@@ -38,6 +38,7 @@ module ActiveFedora
|
|
38
38
|
def has_many(association_id, options={})
|
39
39
|
raise "You must specify a property name for #{name}" if !options[:property]
|
40
40
|
reflection = create_has_many_reflection(association_id, options)
|
41
|
+
add_association_callbacks(reflection.name, reflection.options)
|
41
42
|
collection_accessor_methods(reflection, HasManyAssociation)
|
42
43
|
end
|
43
44
|
|
@@ -152,7 +153,7 @@ module ActiveFedora
|
|
152
153
|
reflection = create_has_and_belongs_to_many_reflection(association_id, options, &extension)
|
153
154
|
collection_accessor_methods(reflection, HasAndBelongsToManyAssociation)
|
154
155
|
#configure_after_destroy_method_for_has_and_belongs_to_many(reflection)
|
155
|
-
|
156
|
+
add_association_callbacks(reflection.name, options)
|
156
157
|
end
|
157
158
|
|
158
159
|
|
@@ -171,6 +172,20 @@ module ActiveFedora
|
|
171
172
|
create_reflection(:has_and_belongs_to_many, association_id, options, self)
|
172
173
|
end
|
173
174
|
|
175
|
+
def add_association_callbacks(association_name, options)
|
176
|
+
callbacks = %w(before_add after_add before_remove after_remove)
|
177
|
+
callbacks.each do |callback_name|
|
178
|
+
full_callback_name = "#{callback_name}_for_#{association_name}"
|
179
|
+
defined_callbacks = options[callback_name.to_sym]
|
180
|
+
class_attribute full_callback_name.to_sym
|
181
|
+
if options.has_key?(callback_name.to_sym)
|
182
|
+
self.send((full_callback_name +'=').to_sym, [defined_callbacks].flatten)
|
183
|
+
else
|
184
|
+
self.send((full_callback_name +'=').to_sym, [])
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
174
189
|
def association_accessor_methods(reflection, association_proxy_class)
|
175
190
|
redefine_method(reflection.name) do |*params|
|
176
191
|
force_reload = params.first unless params.empty?
|
@@ -215,10 +215,28 @@ module ActiveFedora
|
|
215
215
|
records = flatten_deeper(records)
|
216
216
|
records.each { |record| raise_on_type_mismatch(record) }
|
217
217
|
|
218
|
-
|
218
|
+
records.each { |record| callback(:before_remove, record) }
|
219
219
|
old_records = records.reject { |r| r.new_record? }
|
220
220
|
yield(records, old_records)
|
221
|
-
|
221
|
+
records.each { |record| callback(:after_remove, record) }
|
222
|
+
end
|
223
|
+
|
224
|
+
def callback(method, record)
|
225
|
+
callbacks_for(method).each do |callback|
|
226
|
+
case callback
|
227
|
+
when Symbol
|
228
|
+
@owner.send(callback, record)
|
229
|
+
when Proc
|
230
|
+
callback.call(@owner, record)
|
231
|
+
else
|
232
|
+
callback.send(method, @owner, record)
|
233
|
+
end
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
237
|
+
def callbacks_for(callback_name)
|
238
|
+
full_callback_name = "#{callback_name}_for_#{@reflection.name}"
|
239
|
+
@owner.class.send(full_callback_name.to_sym) || []
|
222
240
|
end
|
223
241
|
|
224
242
|
def ensure_owner_is_not_new
|
@@ -48,10 +48,17 @@ module ActiveFedora
|
|
48
48
|
|
49
49
|
if (@reflection.options[:inverse_of])
|
50
50
|
r.remove_relationship(@reflection.options[:inverse_of], @owner)
|
51
|
+
# It looks like inverse_of points at a predicate, not at a relationship name,
|
52
|
+
# which is what we should have done. Now we need a way to look up the
|
53
|
+
# reflection by predicate
|
54
|
+
name = r.class.reflection_name_for_predicate(@reflection.options[:inverse_of])
|
55
|
+
r.send(name).reset
|
51
56
|
r.save
|
52
57
|
end
|
53
58
|
end
|
59
|
+
@owner.save!
|
54
60
|
end
|
61
|
+
|
55
62
|
end
|
56
63
|
end
|
57
64
|
end
|
data/lib/active_fedora/base.rb
CHANGED
@@ -30,8 +30,7 @@ module ActiveFedora
|
|
30
30
|
self.fedora_connection = {}
|
31
31
|
self.profile_solr_name = ActiveFedora::SolrService.solr_name("object_profile", :displayable)
|
32
32
|
|
33
|
-
delegate :label
|
34
|
-
delegate :state=, :state, to: :inner_object
|
33
|
+
delegate :state=,:label=, to: :inner_object
|
35
34
|
|
36
35
|
def method_missing(name, *args)
|
37
36
|
dsid = corresponding_datastream_name(name)
|
@@ -64,6 +63,19 @@ module ActiveFedora
|
|
64
63
|
!new_object?
|
65
64
|
end
|
66
65
|
|
66
|
+
def mark_for_destruction
|
67
|
+
@marked_for_destruction = true
|
68
|
+
end
|
69
|
+
|
70
|
+
def marked_for_destruction?
|
71
|
+
@marked_for_destruction
|
72
|
+
end
|
73
|
+
|
74
|
+
def reload(options = nil)
|
75
|
+
@marked_for_destruction = false
|
76
|
+
super
|
77
|
+
end
|
78
|
+
|
67
79
|
# Constructor. You may supply a custom +:pid+, or we call the Fedora Rest API for the
|
68
80
|
# next available Fedora pid, and mark as new object.
|
69
81
|
# Also, if +attrs+ does not contain +:pid+ but does contain +:namespace+ it will pass the
|
@@ -184,9 +196,7 @@ module ActiveFedora
|
|
184
196
|
credentials = ActiveFedora.config.credentials
|
185
197
|
end
|
186
198
|
fedora_connection[0] ||= ActiveFedora::RubydoraConnection.new(credentials)
|
187
|
-
|
188
|
-
pid = d.xpath('//fedora:pid', 'fedora' => 'http://www.fedora.info/definitions/1/0/management/').text
|
189
|
-
pid
|
199
|
+
fedora_connection[0].connection.mint(args)
|
190
200
|
end
|
191
201
|
|
192
202
|
def inner_object # :nodoc
|
@@ -220,21 +230,35 @@ module ActiveFedora
|
|
220
230
|
|
221
231
|
#return the owner id
|
222
232
|
def owner_id
|
223
|
-
@inner_object.ownerId
|
233
|
+
Array(@inner_object.ownerId).first
|
224
234
|
end
|
225
235
|
|
226
236
|
def owner_id=(owner_id)
|
227
237
|
@inner_object.ownerId=(owner_id)
|
228
238
|
end
|
229
239
|
|
240
|
+
def label
|
241
|
+
Array(@inner_object.label).first
|
242
|
+
end
|
243
|
+
|
244
|
+
def state
|
245
|
+
Array(@inner_object.state).first
|
246
|
+
end
|
247
|
+
|
230
248
|
#return the create_date of the inner object (unless it's a new object)
|
231
249
|
def create_date
|
232
|
-
@inner_object.new?
|
250
|
+
if @inner_object.new?
|
251
|
+
Time.now
|
252
|
+
elsif @inner_object.respond_to? :createdDate
|
253
|
+
Array(@inner_object.createdDate).first
|
254
|
+
else
|
255
|
+
@inner_object.profile['objCreateDate']
|
256
|
+
end
|
233
257
|
end
|
234
258
|
|
235
259
|
#return the modification date of the inner object (unless it's a new object)
|
236
260
|
def modified_date
|
237
|
-
@inner_object.new? ? Time.now : @inner_object.
|
261
|
+
@inner_object.new? ? Time.now : Array(@inner_object.lastModifiedDate).first
|
238
262
|
end
|
239
263
|
|
240
264
|
def ==(comparison_object)
|
@@ -10,6 +10,13 @@ module ActiveFedora
|
|
10
10
|
super
|
11
11
|
end
|
12
12
|
|
13
|
+
alias_method :realLabel, :label
|
14
|
+
|
15
|
+
def label
|
16
|
+
Array(realLabel).first
|
17
|
+
end
|
18
|
+
alias_method :dsLabel, :label
|
19
|
+
|
13
20
|
def inspect
|
14
21
|
"#<#{self.class} @pid=\"#{digital_object ? pid : nil}\" @dsid=\"#{dsid}\" @controlGroup=\"#{controlGroup}\" changed=\"#{changed?}\" @mimeType=\"#{mimeType}\" >"
|
15
22
|
end
|
@@ -123,6 +123,7 @@ module ActiveFedora
|
|
123
123
|
# Return the Dublin Core (DC) Datastream. You can also get at this via
|
124
124
|
# the +datastreams["DC"]+.
|
125
125
|
def dc
|
126
|
+
Deprecation.warn(Datastreams, 'dc is deprecated. Consider using Base#datastreams["DC"] instead.', caller)
|
126
127
|
return datastreams["DC"]
|
127
128
|
end
|
128
129
|
|
@@ -5,6 +5,9 @@ require 'active_support/core_ext/object/blank'
|
|
5
5
|
|
6
6
|
module ActiveFedora
|
7
7
|
module NestedAttributes #:nodoc:
|
8
|
+
class TooManyRecords < RuntimeError
|
9
|
+
end
|
10
|
+
|
8
11
|
extend ActiveSupport::Concern
|
9
12
|
included do
|
10
13
|
class_attribute :nested_attributes_options, :instance_writer => false
|
@@ -50,10 +53,12 @@ module ActiveFedora
|
|
50
53
|
# # creates avatar_attributes= and posts_attributes=
|
51
54
|
# accepts_nested_attributes_for :avatar, :posts, :allow_destroy => true
|
52
55
|
module ClassMethods
|
56
|
+
REJECT_ALL_BLANK_PROC = proc { |attributes| attributes.all? { |key, value| key == '_destroy' || value.blank? } }
|
57
|
+
|
53
58
|
def accepts_nested_attributes_for(*attr_names)
|
54
59
|
options = { :allow_destroy => false, :update_only => false }
|
55
60
|
options.update(attr_names.extract_options!)
|
56
|
-
|
61
|
+
options.assert_valid_keys(:allow_destroy, :reject_if, :limit, :update_only)
|
57
62
|
options[:reject_if] = REJECT_ALL_BLANK_PROC if options[:reject_if] == :all_blank
|
58
63
|
|
59
64
|
attr_names.each do |association_name|
|
@@ -61,20 +66,23 @@ module ActiveFedora
|
|
61
66
|
reflection.options[:autosave] = true
|
62
67
|
# add_autosave_association_callbacks(reflection)
|
63
68
|
## TODO this ought to work, but doesn't seem to do the class inheitance right
|
69
|
+
|
70
|
+
nested_attributes_options = self.nested_attributes_options.dup
|
64
71
|
nested_attributes_options[association_name.to_sym] = options
|
72
|
+
self.nested_attributes_options = nested_attributes_options
|
73
|
+
|
65
74
|
type = (reflection.collection? ? :collection : :one_to_one)
|
66
75
|
|
67
76
|
# def pirate_attributes=(attributes)
|
68
77
|
# assign_nested_attributes_for_one_to_one_association(:pirate, attributes)
|
69
78
|
# end
|
70
79
|
class_eval <<-eoruby, __FILE__, __LINE__ + 1
|
71
|
-
|
72
|
-
|
73
|
-
end
|
80
|
+
remove_possible_method(:#{association_name}_attributes=)
|
81
|
+
|
74
82
|
def #{association_name}_attributes=(attributes)
|
75
83
|
assign_nested_attributes_for_#{type}_association(:#{association_name}, attributes)
|
76
84
|
## in lieu of autosave_association_callbacks just save all of em.
|
77
|
-
send(:#{association_name}).each {|obj| obj.save}
|
85
|
+
send(:#{association_name}).each {|obj| obj.marked_for_destruction? ? obj.destroy : obj.save}
|
78
86
|
end
|
79
87
|
eoruby
|
80
88
|
else
|
@@ -92,8 +100,12 @@ module ActiveFedora
|
|
92
100
|
|
93
101
|
|
94
102
|
def assign_nested_attributes_for_collection_association(association_name, attributes_collection)
|
95
|
-
options=
|
96
|
-
|
103
|
+
options = nested_attributes_options[association_name]
|
104
|
+
|
105
|
+
if options[:limit] && attributes_collection.size > options[:limit]
|
106
|
+
raise TooManyRecords, "Maximum #{options[:limit]} records are allowed. Got #{attributes_collection.size} records instead."
|
107
|
+
end
|
108
|
+
|
97
109
|
if attributes_collection.is_a? Hash
|
98
110
|
keys = attributes_collection.keys
|
99
111
|
attributes_collection = if keys.include?('id') || keys.include?(:id)
|
@@ -116,11 +128,14 @@ module ActiveFedora
|
|
116
128
|
attributes = attributes.with_indifferent_access
|
117
129
|
|
118
130
|
if attributes['id'].blank?
|
119
|
-
association.build(attributes.except(*UNASSIGNABLE_KEYS))
|
131
|
+
association.build(attributes.except(*UNASSIGNABLE_KEYS)) unless call_reject_if(association_name, attributes)
|
120
132
|
|
121
133
|
elsif existing_record = existing_records.detect { |record| record.id.to_s == attributes['id'].to_s }
|
122
134
|
association.send(:add_record_to_target_with_callbacks, existing_record) if !association.loaded? && !call_reject_if(association_name, attributes)
|
123
|
-
|
135
|
+
|
136
|
+
if !call_reject_if(association_name, attributes)
|
137
|
+
assign_to_or_mark_for_destruction(existing_record, attributes, options[:allow_destroy])
|
138
|
+
end
|
124
139
|
|
125
140
|
else
|
126
141
|
raise_nested_attributes_record_not_found(association_name, attributes['id'])
|
@@ -146,6 +161,16 @@ module ActiveFedora
|
|
146
161
|
raise ObjectNotFoundError, "Couldn't find #{reflection.klass.name} with ID=#{record_id} for #{self.class.name} with ID=#{id}"
|
147
162
|
end
|
148
163
|
|
164
|
+
def call_reject_if(association_name, attributes)
|
165
|
+
return false if has_destroy_flag?(attributes)
|
166
|
+
case callback = self.nested_attributes_options[association_name][:reject_if]
|
167
|
+
when Symbol
|
168
|
+
method(callback).arity == 0 ? send(callback) : send(callback, attributes)
|
169
|
+
when Proc
|
170
|
+
callback.call(attributes)
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
149
174
|
end
|
150
175
|
end
|
151
176
|
|
@@ -7,9 +7,13 @@ module ActiveFedora
|
|
7
7
|
self.reflections = {}
|
8
8
|
end
|
9
9
|
|
10
|
-
|
11
|
-
|
12
10
|
module ClassMethods
|
11
|
+
def reflection_name_for_predicate(predicate)
|
12
|
+
reflections.each do |k, v|
|
13
|
+
return k if v.options[:property] == predicate
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
13
17
|
def create_reflection(macro, name, options, active_fedora)
|
14
18
|
case macro
|
15
19
|
when :has_many, :belongs_to, :has_and_belongs_to_many
|
@@ -55,12 +59,9 @@ module ActiveFedora
|
|
55
59
|
# a new association object. Use +build_association+ or +create_association+
|
56
60
|
# instead. This allows plugins to hook into association object creation.
|
57
61
|
def klass
|
58
|
-
|
59
|
-
@klass ||= class_name
|
62
|
+
@klass ||= class_name.constantize
|
60
63
|
end
|
61
64
|
|
62
|
-
|
63
|
-
|
64
65
|
def initialize(macro, name, options, active_fedora)
|
65
66
|
@macro, @name, @options, @active_fedora = macro, name, options, active_fedora
|
66
67
|
end
|
@@ -73,36 +74,23 @@ module ActiveFedora
|
|
73
74
|
|
74
75
|
# Returns the name of the macro.
|
75
76
|
#
|
76
|
-
# <tt>composed_of :balance, :class_name => 'Money'</tt> returns <tt>:balance</tt>
|
77
77
|
# <tt>has_many :clients</tt> returns <tt>:clients</tt>
|
78
78
|
attr_reader :name
|
79
79
|
|
80
|
-
|
81
80
|
# Returns the hash of options used for the macro.
|
82
81
|
#
|
83
|
-
# <tt>composed_of :balance, :class_name => 'Money'</tt> returns <tt>{ :class_name => "Money" }</tt>
|
84
82
|
# <tt>has_many :clients</tt> returns +{}+
|
85
83
|
attr_reader :options
|
86
84
|
|
87
85
|
attr_reader :macro
|
88
86
|
|
89
|
-
# Returns the class for the macro.
|
90
|
-
#
|
91
|
-
# <tt>composed_of :balance, :class_name => 'Money'</tt> returns the Money class
|
92
|
-
# <tt>has_many :clients</tt> returns the Client class
|
93
|
-
def klass
|
94
|
-
@klass ||= class_name.constantize
|
95
|
-
end
|
96
|
-
|
97
87
|
# Returns the class name for the macro.
|
98
88
|
#
|
99
|
-
# <tt>composed_of :balance, :class_name => 'Money'</tt> returns <tt>'Money'</tt>
|
100
89
|
# <tt>has_many :clients</tt> returns <tt>'Client'</tt>
|
101
90
|
def class_name
|
102
91
|
@class_name ||= options[:class_name] || derive_class_name
|
103
92
|
end
|
104
93
|
|
105
|
-
|
106
94
|
# Returns whether or not this association reflection is for a collection
|
107
95
|
# association. Returns +true+ if the +macro+ is either +has_many+ or
|
108
96
|
# +has_and_belongs_to_many+, +false+ otherwise.
|
@@ -110,8 +98,6 @@ module ActiveFedora
|
|
110
98
|
@collection
|
111
99
|
end
|
112
100
|
|
113
|
-
|
114
|
-
|
115
101
|
private
|
116
102
|
def derive_class_name
|
117
103
|
class_name = name.to_s.camelize
|
@@ -119,7 +105,6 @@ module ActiveFedora
|
|
119
105
|
class_name
|
120
106
|
end
|
121
107
|
|
122
|
-
|
123
108
|
end
|
124
109
|
|
125
110
|
# Holds all the meta-data about an association as it was specified in the
|
@@ -134,7 +119,6 @@ module ActiveFedora
|
|
134
119
|
def primary_key_name
|
135
120
|
@primary_key_name ||= options[:foreign_key] || derive_primary_key_name
|
136
121
|
end
|
137
|
-
|
138
122
|
|
139
123
|
# Creates a new instance of the associated class, and immediately saves it
|
140
124
|
# with ActiveRecord::Base#save. +options+ will be passed to the class's
|
@@ -143,8 +127,6 @@ module ActiveFedora
|
|
143
127
|
klass.create(*options)
|
144
128
|
end
|
145
129
|
|
146
|
-
|
147
|
-
|
148
130
|
private
|
149
131
|
|
150
132
|
def derive_primary_key_name
|