active-fedora 9.1.2 → 9.2.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (101) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +1 -1
  3. data/Gemfile +1 -0
  4. data/History.txt +90 -0
  5. data/active-fedora.gemspec +2 -2
  6. data/lib/active_fedora.rb +17 -3
  7. data/lib/active_fedora/associations.rb +77 -0
  8. data/lib/active_fedora/associations/association.rb +2 -2
  9. data/lib/active_fedora/associations/basic_contains_association.rb +52 -0
  10. data/lib/active_fedora/associations/builder/directly_contains.rb +23 -0
  11. data/lib/active_fedora/associations/builder/directly_contains_one.rb +44 -0
  12. data/lib/active_fedora/associations/builder/has_and_belongs_to_many.rb +2 -23
  13. data/lib/active_fedora/associations/builder/indirectly_contains.rb +26 -0
  14. data/lib/active_fedora/associations/builder/property.rb +10 -0
  15. data/lib/active_fedora/associations/collection_association.rb +42 -45
  16. data/lib/active_fedora/associations/collection_proxy.rb +6 -0
  17. data/lib/active_fedora/associations/contained_finder.rb +41 -0
  18. data/lib/active_fedora/associations/container_proxy.rb +9 -0
  19. data/lib/active_fedora/associations/contains_association.rb +20 -38
  20. data/lib/active_fedora/associations/delete_proxy.rb +28 -0
  21. data/lib/active_fedora/associations/directly_contains_association.rb +56 -0
  22. data/lib/active_fedora/associations/directly_contains_one_association.rb +113 -0
  23. data/lib/active_fedora/associations/has_and_belongs_to_many_association.rb +6 -14
  24. data/lib/active_fedora/associations/has_many_association.rb +0 -3
  25. data/lib/active_fedora/associations/id_composite.rb +30 -0
  26. data/lib/active_fedora/associations/indirectly_contains_association.rb +90 -0
  27. data/lib/active_fedora/associations/rdf.rb +8 -4
  28. data/lib/active_fedora/associations/record_composite.rb +39 -0
  29. data/lib/active_fedora/attached_files.rb +1 -1
  30. data/lib/active_fedora/attributes.rb +28 -10
  31. data/lib/active_fedora/attributes/active_triple_attribute.rb +17 -0
  32. data/lib/active_fedora/attributes/om_attribute.rb +29 -0
  33. data/lib/active_fedora/attributes/rdf_datastream_attribute.rb +47 -0
  34. data/lib/active_fedora/attributes/stream_attribute.rb +46 -0
  35. data/lib/active_fedora/autosave_association.rb +2 -2
  36. data/lib/active_fedora/base.rb +3 -0
  37. data/lib/active_fedora/containers/container.rb +38 -0
  38. data/lib/active_fedora/containers/direct_container.rb +5 -0
  39. data/lib/active_fedora/containers/indirect_container.rb +7 -0
  40. data/lib/active_fedora/core.rb +4 -48
  41. data/lib/active_fedora/delegated_attribute.rb +5 -98
  42. data/lib/active_fedora/fedora.rb +1 -1
  43. data/lib/active_fedora/fedora_attributes.rb +4 -26
  44. data/lib/active_fedora/file.rb +87 -159
  45. data/lib/active_fedora/file/attributes.rb +63 -0
  46. data/lib/active_fedora/file/streaming.rb +46 -0
  47. data/lib/active_fedora/file_relation.rb +7 -0
  48. data/lib/active_fedora/identifiable.rb +87 -0
  49. data/lib/active_fedora/inbound_relation_connection.rb +21 -0
  50. data/lib/active_fedora/indexers.rb +10 -0
  51. data/lib/active_fedora/indexers/global_indexer.rb +30 -0
  52. data/lib/active_fedora/indexers/null_indexer.rb +12 -0
  53. data/lib/active_fedora/indexing/map.rb +4 -5
  54. data/lib/active_fedora/indexing_service.rb +3 -22
  55. data/lib/active_fedora/loadable_from_json.rb +8 -0
  56. data/lib/active_fedora/pathing.rb +24 -0
  57. data/lib/active_fedora/persistence.rb +15 -8
  58. data/lib/active_fedora/rdf.rb +2 -0
  59. data/lib/active_fedora/rdf/fcrepo4.rb +1 -0
  60. data/lib/active_fedora/rdf/field_map.rb +90 -0
  61. data/lib/active_fedora/rdf/field_map_entry.rb +28 -0
  62. data/lib/active_fedora/rdf/indexing_service.rb +9 -23
  63. data/lib/active_fedora/rdf/rdf_datastream.rb +1 -2
  64. data/lib/active_fedora/reflection.rb +16 -15
  65. data/lib/active_fedora/relation/delegation.rb +15 -4
  66. data/lib/active_fedora/relation/finder_methods.rb +4 -4
  67. data/lib/active_fedora/schema.rb +26 -0
  68. data/lib/active_fedora/schema_indexing_strategy.rb +25 -0
  69. data/lib/active_fedora/simple_datastream.rb +2 -2
  70. data/lib/active_fedora/solr_query_builder.rb +3 -2
  71. data/lib/active_fedora/version.rb +1 -1
  72. data/lib/active_fedora/with_metadata.rb +1 -1
  73. data/spec/integration/associations/rdf_spec.rb +49 -0
  74. data/spec/integration/base_spec.rb +19 -0
  75. data/spec/integration/belongs_to_association_spec.rb +6 -6
  76. data/spec/integration/collection_association_spec.rb +4 -4
  77. data/spec/integration/complex_rdf_datastream_spec.rb +12 -12
  78. data/spec/integration/datastream_rdf_nested_attributes_spec.rb +1 -1
  79. data/spec/integration/direct_container_spec.rb +254 -0
  80. data/spec/integration/directly_contains_one_association_spec.rb +102 -0
  81. data/spec/integration/file_spec.rb +16 -5
  82. data/spec/integration/has_many_associations_spec.rb +93 -58
  83. data/spec/integration/indirect_container_spec.rb +251 -0
  84. data/spec/integration/rdf_nested_attributes_spec.rb +1 -1
  85. data/spec/integration/relation_spec.rb +43 -27
  86. data/spec/spec_helper.rb +1 -1
  87. data/spec/unit/attributes_spec.rb +6 -6
  88. data/spec/unit/collection_proxy_spec.rb +28 -0
  89. data/spec/unit/file_spec.rb +1 -1
  90. data/spec/unit/files_hash_spec.rb +4 -4
  91. data/spec/unit/has_and_belongs_to_many_association_spec.rb +11 -9
  92. data/spec/unit/indexers/global_indexer_spec.rb +41 -0
  93. data/spec/unit/indexing_service_spec.rb +0 -21
  94. data/spec/unit/loadable_from_json_spec.rb +31 -0
  95. data/spec/unit/pathing_spec.rb +37 -0
  96. data/spec/unit/rdf/indexing_service_spec.rb +3 -3
  97. data/spec/unit/rdf_resource_datastream_spec.rb +26 -7
  98. data/spec/unit/schema_indexing_strategy_spec.rb +68 -0
  99. data/spec/unit/solr_query_builder_spec.rb +1 -1
  100. data/spec/unit/solr_service_spec.rb +1 -1
  101. metadata +49 -8
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: da18bdd03d130d9d80945cd2c2ce0cbbe6056831
4
- data.tar.gz: 7709031721c4ccb85bf411d49d61731b097de430
3
+ metadata.gz: 8342f8e77df84a1256f26396de99577f34010d2a
4
+ data.tar.gz: 87203d5509bac4250d9a8c02082b31a310de971f
5
5
  SHA512:
6
- metadata.gz: 3e685a07394f367818b44898dba0c8d059dfec46702534f915840cae1dabda372f50ebe60eb68962295186e588b76dced9624861b545e3611bb83fa89e60737c
7
- data.tar.gz: 048eb130c747e5e96be4593b25c4ab51ccf7fee443df5aa8c67c91108f839f50b01dc8455c86a07cef1417a238e54385d4d2f092138abb17e1797a7a292b359c
6
+ metadata.gz: 407aab67f7584c962bc16c24b0a9f8fc8c25b7d25c7c5d92dd83ee7dbad9cc75b4800fdb7c267790ea4c0879fccc03bcc52da344601e3596b3e4f3214e462dd2
7
+ data.tar.gz: c23c707171608bc46666cfa2c45b45313cf7fdfedc4e656b3b50458565888b35625fd3e3acc5efc77b80fa6b19aa72226d2c2a62870a6343325b89b2bbb929e5
@@ -2,7 +2,7 @@ language: ruby
2
2
  cache: bundler
3
3
  sudo: false
4
4
  rvm:
5
- - 2.2
5
+ - 2.2.1
6
6
 
7
7
  gemfile:
8
8
  - gemfiles/rails4.1.gemfile
data/Gemfile CHANGED
@@ -5,6 +5,7 @@ source "https://rubygems.org"
5
5
  gemspec path: File.expand_path('..', __FILE__)
6
6
 
7
7
  gem 'byebug' unless ENV['TRAVIS']
8
+ gem 'pry-byebug' unless ENV['CI']
8
9
 
9
10
  group :test do
10
11
  gem 'simplecov', require: false
@@ -1,3 +1,93 @@
1
+ v9.2.0.rc1
2
+ 2015-06-30: Refactor CollectionAssociation#reset [Justin Coyne]
3
+
4
+ 2015-06-30: make CollectionAssociation#find_target private [Justin Coyne]
5
+
6
+ 2015-06-25: Implements delete for direct containers. [Hector Correa]
7
+
8
+ 2015-06-29: The uri() method should return an RDF::URI instead of a string
9
+ [Justin Coyne]
10
+
11
+ 2015-06-29: Refactor File#== to avoid an unnecessary API call The new_record?
12
+ call used to cause an API call to fedora, which we are now able to avoid.
13
+ [Justin Coyne]
14
+
15
+ 2015-06-26: Allow File constructor to take a block. Enables removing several
16
+ TODOs about using `tap` [Justin Coyne]
17
+
18
+ 2015-06-26: Avoid unnecessary solr query If only one property has been defined
19
+ for a predicate, there's no reason to run a query to filter the results by
20
+ class. This avoids a call to solr that is unnecessary in most situations.
21
+ [Justin Coyne]
22
+
23
+ 2015-06-26: For an AF record the primary key is always `id` [Justin Coyne]
24
+
25
+ 2015-06-26: Use the solr terms query when fetching by id This allows the query
26
+ to be smaller and more understandable [Justin Coyne]
27
+
28
+ 2015-06-25: RDF::IndexingService indexes objects & properties [Adam Wead]
29
+ true/false depending on whether something was saved or not. [Hector Correa]
30
+
31
+ 2015-06-24: Reorganizing ActiveFedora:File code [Adam Wead]
32
+
33
+ 2015-06-24: Make autosave tests more specific [Adam Wead]
34
+
35
+ 2015-06-24: Use foreign_key in case user has specified one [Adam Wead]
36
+
37
+ 2015-06-24: Refactoring ActiveFedora::File to use ActiveFedora::Persistence
38
+ changed WithMetadata to override create_or_update instead of save so that it
39
+ gets called when you call save or save! [Carolyn Cole]
40
+
41
+ 2015-06-24: Removing unneeded line [Carolyn Cole]
42
+
43
+ 2015-05-02: Add optional prefix to resource URI [Adam Wead]
44
+
45
+ 2015-06-24: refactoring equals [Carolyn Cole]
46
+
47
+ 2015-06-24: Removing dead define_destroy_hook method [Adam Wead]
48
+
49
+ 2015-06-24: Refactoring .find_target for HasAndBelongsToMany [Adam Wead]
50
+
51
+ 2015-06-18: Implements directly_contains_one association Note: part of this
52
+ functionality is blocked by #794 [Matt Zumwalt]
53
+
54
+ 2015-06-24: Return relation for .limit, fixes #352 [Carolyn Cole]
55
+
56
+ 2015-06-23: Refactoring DelegateAttribute [Adam Wead]
57
+
58
+ 2015-06-18: Create a blacklist to disallow mutating relations [Justin Coyne]
59
+
60
+ 2015-06-15: Add documentation to apply_schema. [Trey Terrell]
61
+
62
+ 2015-06-04: Add apply_schema support to AF. [Trey Terrell]
63
+
64
+ 2015-06-11: Remove unnecessary dependency on rdf-vocab [Justin Coyne]
65
+
66
+ 2015-05-18: Direct/Indirect containers should have an include? method [Justin
67
+ Coyne]
68
+
69
+ 2015-05-18: A SolrBackedResource should be enumerable [Justin Coyne]
70
+
71
+ 2015-05-13: Refactor Deleting Indirect Proxies [Trey Terrell]
72
+
73
+ 2015-04-29: Update ActiveTriples [Trey Terrell]
74
+
75
+ 2015-05-13: Translation procs should not overwrite one another [Justin Coyne]
76
+
77
+ 2015-05-13: Fix Deletion of Indirect Container Proxies [Trey Terrell]
78
+
79
+ 2015-05-11: Update Travis to support YARD [Trey Terrell]
80
+
81
+ 2015-05-11: Delete proxies. [Trey Terrell]
82
+
83
+ 2015-05-11: Add spec for deleting indirect items. [Trey Terrell]
84
+
85
+ 2015-05-08: Request Inbound Relations [Trey Terrell]
86
+
87
+ 2015-05-07: Added ldp:IndirectContainer [Justin Coyne]
88
+
89
+ 2015-05-06: Add direct containers [Justin Coyne]
90
+
1
91
  v9.1.2
2
92
  2015-06-11: Remove unnecessary dependency on rdf-vocab [Justin Coyne]
3
93
 
@@ -18,11 +18,11 @@ Gem::Specification.new do |s|
18
18
  s.add_dependency 'om', '~> 3.1'
19
19
  s.add_dependency 'nom-xml', '>= 0.5.1'
20
20
  s.add_dependency "activesupport", '>= 4.1.0'
21
- s.add_dependency "active-triples", '~> 0.6.0'
21
+ s.add_dependency "active-triples", '~> 0.7.1'
22
22
  s.add_dependency "rdf-rdfxml", '~> 1.1.0'
23
23
  s.add_dependency "linkeddata"
24
24
  s.add_dependency "deprecation"
25
- s.add_dependency "ldp", '~> 0.3.0'
25
+ s.add_dependency "ldp", '~> 0.3.1'
26
26
 
27
27
  s.add_development_dependency "rdoc"
28
28
  s.add_development_dependency "yard"
@@ -51,23 +51,34 @@ module ActiveFedora #:nodoc:
51
51
  autoload :CleanConnection
52
52
  autoload :Config
53
53
  autoload :Core
54
- autoload_under 'core' do
55
- autoload :FedoraIdTranslator
56
- autoload :FedoraUriTranslator
54
+ autoload_under 'containers' do
55
+ autoload :Container
56
+ autoload :DirectContainer
57
+ autoload :IndirectContainer
57
58
  end
58
59
  autoload :Datastream
59
60
  autoload :Datastreams
60
61
  autoload :DelegatedAttribute
62
+ autoload_under 'attributes' do
63
+ autoload :StreamAttribute
64
+ autoload :ActiveTripleAttribute
65
+ autoload :OmAttribute
66
+ autoload :RdfDatastreamAttribute
67
+ end
61
68
  autoload :Fedora
62
69
  autoload :FedoraAttributes
63
70
  autoload :File
64
71
  autoload :FileConfigurator
65
72
  autoload :FilePathBuilder
73
+ autoload :FileRelation
66
74
  autoload :FilesHash
67
75
  autoload :FixityService
76
+ autoload :Identifiable
77
+ autoload :Indexers
68
78
  autoload :Indexing
69
79
  autoload :IndexingService
70
80
  autoload :InheritableAccessors
81
+ autoload :InboundRelationConnection
71
82
  autoload :LdpCache
72
83
  autoload :LdpResource
73
84
  autoload :LdpResourceService
@@ -77,6 +88,7 @@ module ActiveFedora #:nodoc:
77
88
  autoload :NomDatastream
78
89
  autoload :NullRelation
79
90
  autoload :OmDatastream
91
+ autoload :Pathing
80
92
  autoload :Persistence
81
93
  autoload :ProfileIndexingService
82
94
  autoload :Property
@@ -101,9 +113,11 @@ module ActiveFedora #:nodoc:
101
113
  autoload :FinderMethods
102
114
  end
103
115
 
116
+ autoload :Schema
104
117
  autoload :Scoping
105
118
  autoload :Serialization
106
119
  autoload :SimpleDatastream
120
+ autoload :SchemaIndexingStrategy
107
121
  autoload :SolrInstanceLoader
108
122
  autoload :SolrQueryBuilder
109
123
  autoload :SolrService
@@ -1,3 +1,4 @@
1
+ require 'active_support/core_ext/enumerable'
1
2
  require 'active_support/core_ext/module/delegation'
2
3
  require 'active_support/core_ext/object/blank'
3
4
 
@@ -19,11 +20,20 @@ module ActiveFedora
19
20
  autoload :SingularRDF, 'active_fedora/associations/singular_rdf'
20
21
  autoload :CollectionAssociation, 'active_fedora/associations/collection_association'
21
22
  autoload :CollectionProxy, 'active_fedora/associations/collection_proxy'
23
+ autoload :ContainerProxy, 'active_fedora/associations/container_proxy'
22
24
 
23
25
  autoload :HasManyAssociation, 'active_fedora/associations/has_many_association'
24
26
  autoload :BelongsToAssociation, 'active_fedora/associations/belongs_to_association'
25
27
  autoload :HasAndBelongsToManyAssociation, 'active_fedora/associations/has_and_belongs_to_many_association'
28
+ autoload :BasicContainsAssociation, 'active_fedora/associations/basic_contains_association'
29
+ autoload :DirectlyContainsAssociation, 'active_fedora/associations/directly_contains_association'
30
+ autoload :DirectlyContainsOneAssociation, 'active_fedora/associations/directly_contains_one_association'
31
+ autoload :IndirectlyContainsAssociation, 'active_fedora/associations/indirectly_contains_association'
26
32
  autoload :ContainsAssociation, 'active_fedora/associations/contains_association'
33
+ autoload :DeleteProxy, 'active_fedora/associations/delete_proxy'
34
+ autoload :ContainedFinder, 'active_fedora/associations/contained_finder'
35
+ autoload :RecordComposite, 'active_fedora/associations/record_composite'
36
+ autoload :IDComposite, 'active_fedora/associations/id_composite'
27
37
 
28
38
  module Builder
29
39
  autoload :Association, 'active_fedora/associations/builder/association'
@@ -34,6 +44,9 @@ module ActiveFedora
34
44
  autoload :HasMany, 'active_fedora/associations/builder/has_many'
35
45
  autoload :HasAndBelongsToMany, 'active_fedora/associations/builder/has_and_belongs_to_many'
36
46
  autoload :Contains, 'active_fedora/associations/builder/contains'
47
+ autoload :DirectlyContains, 'active_fedora/associations/builder/directly_contains'
48
+ autoload :DirectlyContainsOne, 'active_fedora/associations/builder/directly_contains_one'
49
+ autoload :IndirectlyContains, 'active_fedora/associations/builder/indirectly_contains'
37
50
 
38
51
  autoload :Property, 'active_fedora/associations/builder/property'
39
52
  autoload :SingularProperty, 'active_fedora/associations/builder/singular_property'
@@ -61,6 +74,14 @@ module ActiveFedora
61
74
  association
62
75
  end
63
76
 
77
+ def delete(*)
78
+ reflections.each_pair do |name, reflection|
79
+ if reflection.macro == :has_many
80
+ association(name.to_sym).delete_all
81
+ end
82
+ end
83
+ super
84
+ end
64
85
 
65
86
  private
66
87
 
@@ -77,6 +98,62 @@ module ActiveFedora
77
98
 
78
99
  module ClassMethods
79
100
 
101
+ # This method is used to declare an ldp:DirectContainer on a resource
102
+ # you must specify an is_member_of_relation or a has_member_relation
103
+ #
104
+ # @param [String] name the handle to refer to this child as
105
+ # @param [Hash] options
106
+ # @option options [String] :class_name ('ActiveFedora::File') The name of the class that will represent the contained resources
107
+ # @option options [RDF::URI] :has_member_relation the rdf predicate to use for the ldp:hasMemberRelation
108
+ # @option options [RDF::URI] :is_member_of_relation the rdf predicate to use for the ldp:isMemberOfRelation
109
+ #
110
+ # example:
111
+ # class FooHistory < ActiveFedora::Base
112
+ # directly_contains :files, has_member_relation:
113
+ # ::RDF::URI.new("http://example.com/hasFiles"), class_name: 'Thing'
114
+ # directly_contains :other_stuff, is_member_of_relation:
115
+ # ::RDF::URI.new("http://example.com/isContainedBy"), class_name: 'Thing'
116
+ # end
117
+ #
118
+ def directly_contains(name, options={})
119
+ Builder::DirectlyContains.build(self, name, { class_name: 'ActiveFedora::File' }.merge(options))
120
+ end
121
+
122
+ def directly_contains_one(name, options={})
123
+ Builder::DirectlyContainsOne.build(self, name, { class_name: 'ActiveFedora::File' }.merge(options))
124
+ end
125
+
126
+ # This method is used to declare an ldp:IndirectContainer on a resource
127
+ # you must specify an is_member_of_relation or a has_member_relation
128
+ #
129
+ # @param [String] name the handle to refer to this child as
130
+ # @param [Hash] options
131
+ # @option options [String] :class_name ('ActiveFedora::File') The name of the class that will represent the contained resources
132
+ # @option options [RDF::URI] :has_member_relation the rdf predicate to use for the ldp:hasMemberRelation
133
+ # @option options [RDF::URI] :is_member_of_relation the rdf predicate to use for the ldp:isMemberOfRelation
134
+ # @option options [RDF::URI] :inserted_content_relation the rdf predicate to use for the ldp:insertedContentRelation
135
+ # @option options [String] :through name of a class to represent the interstitial node
136
+ # @option options [Symbol] :foreign_key property that points at the remote resource
137
+ #
138
+ # example:
139
+ # class Proxy < ActiveFedora::Base
140
+ # belongs_to :proxy_for, predicate: ::RDF::URI.new('http://www.openarchives.org/ore/terms/proxyFor'), class_name: 'ActiveFedora::Base'
141
+ # end
142
+ #
143
+ # class FooHistory < ActiveFedora::Base
144
+ # indirectly_contains :files, has_member_relation: RDF::Vocab::ORE.aggregates,
145
+ # inserted_content_relation: RDF::Vocab::ORE.proxyFor, class_name: 'Thing',
146
+ # through: 'Proxy', foreign_key: :proxy_for
147
+ #
148
+ # indirectly_contains :other_stuff, is_member_of_relation:
149
+ # ::RDF::URI.new("http://example.com/isContainedBy"), class_name: 'Thing',
150
+ # through: 'Proxy', foreign_key: :proxy_for
151
+ # end
152
+ #
153
+ def indirectly_contains(name, options={})
154
+ Builder::IndirectlyContains.build(self, name, options)
155
+ end
156
+
80
157
  def has_many(name, options={})
81
158
  Builder::HasMany.build(self, name, options)
82
159
  end
@@ -24,6 +24,7 @@ module ActiveFedora
24
24
  def reset
25
25
  @loaded = false
26
26
  @target = nil
27
+ @stale_state = nil
27
28
  @inversed = false
28
29
  end
29
30
 
@@ -173,8 +174,7 @@ module ActiveFedora
173
174
  end
174
175
 
175
176
  def build_record(attributes)
176
- # TODO make initalize take a block and get rid of the tap
177
- reflection.build_association(attributes).tap do |record|
177
+ reflection.build_association(attributes) do |record|
178
178
  initialize_attributes(record)
179
179
  end
180
180
  end
@@ -0,0 +1,52 @@
1
+ module ActiveFedora
2
+ module Associations
3
+ class BasicContainsAssociation < SingularAssociation #:nodoc:
4
+ # Implements the reader method, e.g. foo.bar for Foo.has_one :bar
5
+ def reader(force_reload = false)
6
+ super || build
7
+ end
8
+
9
+ def find_target
10
+ reflection.build_association(target_uri) do |record|
11
+ configure_datastream(record) if reflection.options[:block]
12
+ end
13
+ end
14
+
15
+ def target_uri
16
+ "#{owner.uri}/#{reflection.name}"
17
+ end
18
+
19
+ private
20
+
21
+ def raise_on_type_mismatch(record)
22
+ return if record.is_a? LoadableFromJson::SolrBackedMetadataFile
23
+ super
24
+ end
25
+
26
+ def replace(record)
27
+ if record
28
+ raise_on_type_mismatch(record)
29
+ @updated = true
30
+ end
31
+
32
+ self.target = record
33
+ end
34
+
35
+ def new_record(method, attributes)
36
+ record = super
37
+ configure_datastream(record)
38
+ record
39
+ end
40
+
41
+ def configure_datastream(record)
42
+ # If you called has_metadata with a block, pass the block into the File class
43
+ if reflection.options[:block].class == Proc
44
+ reflection.options[:block].call(record)
45
+ end
46
+ if record.new_record? && reflection.options[:autocreate]
47
+ record.datastream_will_change!
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,23 @@
1
+ module ActiveFedora::Associations::Builder
2
+ class DirectlyContains < CollectionAssociation #:nodoc:
3
+ self.macro = :directly_contains
4
+ self.valid_options += [:has_member_relation, :is_member_of_relation]
5
+ self.valid_options -= [:predicate]
6
+
7
+ def build
8
+ reflection = super
9
+ configure_dependency
10
+ reflection
11
+ end
12
+
13
+ def validate_options
14
+ super
15
+ if !options[:has_member_relation] && !options[:is_member_of_relation]
16
+ raise ArgumentError, "You must specify a :has_member_relation or :is_member_of_relation predicate for #{name}"
17
+ elsif !options[:has_member_relation].kind_of?(RDF::URI) && !options[:is_member_of_relation].kind_of?(RDF::URI)
18
+ raise ArgumentError, "Predicate must be a kind of RDF::URI"
19
+ end
20
+ end
21
+ end
22
+ end
23
+
@@ -0,0 +1,44 @@
1
+ module ActiveFedora::Associations::Builder
2
+ class DirectlyContainsOne < SingularAssociation #:nodoc:
3
+ self.macro = :directly_contains_one
4
+ self.valid_options += [:has_member_relation, :is_member_of_relation, :type, :through]
5
+ self.valid_options -= [:predicate]
6
+
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." if !options[:through]
9
+ if options[:through]
10
+ inherit_options_from_association(options[:through])
11
+ end
12
+ super
13
+
14
+ if options[:class_name] == "ActiveFedora::File"
15
+ 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."
16
+ elsif !options[:has_member_relation] && !options[:is_member_of_relation]
17
+ raise ArgumentError, "You must specify a :has_member_relation or :is_member_of_relation predicate for #{name}"
18
+ elsif !options[:has_member_relation].kind_of?(RDF::URI) && !options[:is_member_of_relation].kind_of?(RDF::URI)
19
+ raise ArgumentError, "Predicate must be a kind of RDF::URI"
20
+ end
21
+
22
+ if !options[:type].kind_of?(RDF::URI)
23
+ raise ArgumentError, "You must specify a Type and it must be a kind of RDF::URI"
24
+ end
25
+ end
26
+
27
+ private
28
+
29
+ # Inherits :has_member_relation from the association corresponding to association_name
30
+ # @param [Symbol] association_name of the association to inherit from
31
+ def inherit_options_from_association(association_name)
32
+ associated_through_reflection = lookup_reflection(association_name)
33
+ 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
34
+ 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
35
+ options[:has_member_relation] = associated_through_reflection.options[:has_member_relation] unless options[:has_member_relation]
36
+ options[:class_name] = associated_through_reflection.options[:class_name] unless (options[:class_name] && options[:class_name] != "ActiveFedora::File")
37
+ end
38
+
39
+ def lookup_reflection(association_name)
40
+ model.reflect_on_association(association_name)
41
+ end
42
+
43
+ end
44
+ end