active-fedora 9.13.0 → 10.0.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +0 -19
- data/lib/active_fedora.rb +0 -17
- data/lib/active_fedora/associations.rb +0 -16
- data/lib/active_fedora/associations/builder/association.rb +3 -19
- data/lib/active_fedora/associations/builder/has_and_belongs_to_many.rb +1 -3
- data/lib/active_fedora/attached_files.rb +2 -108
- data/lib/active_fedora/attributes.rb +4 -100
- data/lib/active_fedora/core.rb +0 -6
- data/lib/active_fedora/datastreams.rb +0 -2
- data/lib/active_fedora/errors.rb +0 -9
- data/lib/active_fedora/file.rb +9 -22
- data/lib/active_fedora/file_configurator.rb +1 -32
- data/lib/active_fedora/identifiable.rb +0 -6
- data/lib/active_fedora/ldp_resource.rb +0 -12
- data/lib/active_fedora/qualified_dublin_core_datastream.rb +1 -1
- data/lib/active_fedora/query_result_builder.rb +0 -17
- data/lib/active_fedora/rdf/datastream_indexing.rb +0 -11
- data/lib/active_fedora/rdf/indexing_service.rb +1 -1
- data/lib/active_fedora/rdf/rdf_datastream.rb +0 -10
- data/lib/active_fedora/relation/finder_methods.rb +2 -21
- data/lib/active_fedora/solr_query_builder.rb +0 -16
- data/lib/active_fedora/solr_service.rb +2 -89
- data/lib/active_fedora/version.rb +1 -1
- data/lib/active_fedora/versionable.rb +0 -8
- data/spec/config_helper.rb +0 -4
- data/spec/integration/attached_files_spec.rb +1 -108
- data/spec/integration/attributes_spec.rb +14 -94
- data/spec/integration/direct_container_spec.rb +2 -2
- data/spec/integration/file_spec.rb +23 -13
- data/spec/integration/indexing_spec.rb +4 -4
- data/spec/integration/json_serialization_spec.rb +4 -57
- data/spec/integration/ntriples_datastream_spec.rb +77 -139
- data/spec/integration/relation_delegation_spec.rb +16 -18
- data/spec/integration/{model_spec.rb → scoping_spec.rb} +10 -14
- data/spec/integration/solr_hit_spec.rb +4 -20
- data/spec/integration/solr_instance_loader_spec.rb +1 -13
- data/spec/integration/versionable_spec.rb +0 -9
- data/spec/samples/models/mods_article.rb +1 -6
- data/spec/spec_helper.rb +0 -3
- data/spec/unit/attached_files_spec.rb +29 -127
- data/spec/unit/attributes_spec.rb +51 -475
- data/spec/unit/base_active_model_spec.rb +12 -47
- data/spec/unit/base_extra_spec.rb +1 -1
- data/spec/unit/code_configurator_spec.rb +2 -10
- data/spec/unit/core_spec.rb +3 -18
- data/spec/unit/file_configurator_spec.rb +0 -80
- data/spec/unit/file_spec.rb +0 -6
- data/spec/unit/has_and_belongs_to_many_association_spec.rb +0 -7
- data/spec/unit/inheritance_spec.rb +0 -12
- data/spec/unit/ntriples_datastream_spec.rb +2 -74
- data/spec/unit/property_spec.rb +0 -3
- data/spec/unit/query_spec.rb +0 -7
- data/spec/unit/querying_spec.rb +24 -0
- data/spec/unit/rdf/indexing_service_spec.rb +32 -20
- data/spec/unit/rdf_resource_datastream_spec.rb +37 -97
- data/spec/unit/solr_query_builder_spec.rb +0 -8
- data/spec/unit/solr_service_spec.rb +0 -13
- metadata +6 -19
- data/config/predicate_mappings.yml +0 -51
- data/lib/active_fedora/attributes/om_attribute.rb +0 -26
- data/lib/active_fedora/attributes/rdf_datastream_attribute.rb +0 -44
- data/lib/active_fedora/attributes/stream_attribute.rb +0 -43
- data/lib/active_fedora/datastream.rb +0 -9
- data/lib/active_fedora/model.rb +0 -31
- data/lib/active_fedora/predicates.rb +0 -122
- data/lib/active_fedora/simple_datastream.rb +0 -92
- data/spec/fixtures/rails_root/config/predicate_mappings.yml +0 -31
- data/spec/integration/field_to_solr_name_spec.rb +0 -36
- data/spec/unit/base_datastream_management_spec.rb +0 -19
- data/spec/unit/model_spec.rb +0 -30
- data/spec/unit/predicates_spec.rb +0 -126
- data/spec/unit/simple_datastream_spec.rb +0 -101
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 52036e2b5df62b1f60a9de0775f437b25c3a7007
|
4
|
+
data.tar.gz: 3dfb407e63e75f71b5a4ee179ae3bb269fb9d507
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e8f1330cc76aae3d76639026d5538c559e3b156093138f11ff736a0d0220e5bba0732b4997dc68e43f52fba756c1ebd5c77fa3d406db6ee4d9761837f3ce4cda
|
7
|
+
data.tar.gz: 108479da9acacf1fef63de9d734eaa3c2aa866660b75b5363474ef1283ce04938beb0f71f04eb19cee890a5bfa46cca95f866c47ce454bee36685cc94db0045c
|
data/README.md
CHANGED
@@ -93,25 +93,6 @@ is installed, run:
|
|
93
93
|
rake spec
|
94
94
|
```
|
95
95
|
|
96
|
-
Predicate Mappings
|
97
|
-
------------------
|
98
|
-
|
99
|
-
ActiveFedora versions 2.2.1 and higher provides specialized control over
|
100
|
-
the predicate mappings used by SemanticNode. In order to provide your
|
101
|
-
own mappings,
|
102
|
-
you must supply a `predicate_mappings.yml` in the same format as the
|
103
|
-
`config/predicate_mappings.yml` file shipped with the ActiveFedora gem.
|
104
|
-
Place the file in the same directory
|
105
|
-
as your `fedora.yml` file and use the current method of initializing
|
106
|
-
ActiveFedora:
|
107
|
-
|
108
|
-
```ruby
|
109
|
-
ActiveFedora.init("/path/to/my/config/fedora.yml")
|
110
|
-
```
|
111
|
-
|
112
|
-
If no `predicate_mappings.yml` file is found, ActiveFedora will use the
|
113
|
-
default mappings.
|
114
|
-
|
115
96
|
Acknowledgements
|
116
97
|
----------------
|
117
98
|
|
data/lib/active_fedora.rb
CHANGED
@@ -59,14 +59,10 @@ module ActiveFedora #:nodoc:
|
|
59
59
|
autoload :DirectContainer
|
60
60
|
autoload :IndirectContainer
|
61
61
|
end
|
62
|
-
autoload :Datastream
|
63
62
|
autoload :Datastreams
|
64
63
|
autoload :DelegatedAttribute
|
65
64
|
autoload_under 'attributes' do
|
66
|
-
autoload :StreamAttribute
|
67
65
|
autoload :ActiveTripleAttribute
|
68
|
-
autoload :OmAttribute
|
69
|
-
autoload :RdfDatastreamAttribute
|
70
66
|
end
|
71
67
|
autoload :DefaultModelMapper
|
72
68
|
autoload :Fedora
|
@@ -91,7 +87,6 @@ module ActiveFedora #:nodoc:
|
|
91
87
|
autoload :LdpResource
|
92
88
|
autoload :LdpResourceService
|
93
89
|
autoload :LoadableFromJson
|
94
|
-
autoload :Model
|
95
90
|
autoload :ModelClassifier
|
96
91
|
autoload :NestedAttributes
|
97
92
|
autoload :NomDatastream
|
@@ -127,14 +122,12 @@ module ActiveFedora #:nodoc:
|
|
127
122
|
autoload :Schema
|
128
123
|
autoload :Scoping
|
129
124
|
autoload :Serialization
|
130
|
-
autoload :SimpleDatastream
|
131
125
|
autoload :SchemaIndexingStrategy
|
132
126
|
autoload :SolrHit
|
133
127
|
autoload :SolrInstanceLoader
|
134
128
|
autoload :SolrQueryBuilder
|
135
129
|
autoload :SolrService
|
136
130
|
autoload :SparqlInsert
|
137
|
-
autoload :Predicates
|
138
131
|
autoload :Type
|
139
132
|
autoload :Validations
|
140
133
|
autoload :Versionable
|
@@ -172,8 +165,6 @@ module ActiveFedora #:nodoc:
|
|
172
165
|
end
|
173
166
|
end
|
174
167
|
|
175
|
-
extend Deprecation
|
176
|
-
|
177
168
|
class << self
|
178
169
|
attr_reader :fedora_config, :solr_config, :config_options
|
179
170
|
attr_accessor :configurator
|
@@ -198,7 +189,6 @@ module ActiveFedora #:nodoc:
|
|
198
189
|
end
|
199
190
|
@fedora_config = nil
|
200
191
|
SolrService.reset!
|
201
|
-
Predicates.predicate_config = nil
|
202
192
|
configurator.init(options)
|
203
193
|
end
|
204
194
|
|
@@ -234,17 +224,10 @@ module ActiveFedora #:nodoc:
|
|
234
224
|
ActiveFedora::SolrService.instance
|
235
225
|
end
|
236
226
|
|
237
|
-
def reset_fedora!
|
238
|
-
Deprecation.warn(ActiveFedora, 'ActiveFedora.reset_fedora! is deprecated; use ActiveFedora::Fedora.reset! instead. This will be removed in active-fedora 10.0')
|
239
|
-
ActiveFedora::Fedora.reset!
|
240
|
-
end
|
241
|
-
|
242
227
|
def fedora
|
243
228
|
ActiveFedora::Fedora.instance
|
244
229
|
end
|
245
230
|
|
246
|
-
delegate :predicate_config, to: :configurator
|
247
|
-
|
248
231
|
def root
|
249
232
|
::File.expand_path('../..', __FILE__)
|
250
233
|
end
|
@@ -183,22 +183,6 @@ module ActiveFedora
|
|
183
183
|
Builder::HasMany.build(self, name, options)
|
184
184
|
end
|
185
185
|
|
186
|
-
# This method is used to specify the details of a contained resource.
|
187
|
-
# Pass the name as the first argument and a hash of options as the second argument
|
188
|
-
# Note that this method doesn't actually execute the block, but stores it, to be executed
|
189
|
-
# by any the implementation of the resource(specified as :class_name)
|
190
|
-
#
|
191
|
-
# @param [String] name the handle to refer to this child as
|
192
|
-
# @param [Hash] options
|
193
|
-
# @option options [Class] :class_name The class that will represent this child, should extend ``ActiveFedora::File'' or ``ActiveFedora::Base''
|
194
|
-
# @option options [String] :url
|
195
|
-
# @option options [Boolean] :autocreate Always create this resource on new objects
|
196
|
-
# @yield block executed by some types of child resources
|
197
|
-
def contains(name, options = {}, &block)
|
198
|
-
Deprecation.warn(Associations, "contains is deprecated. Use has_subresource instead. This will be removed in ActiveFedora 10")
|
199
|
-
has_subresource(name, options, &block)
|
200
|
-
end
|
201
|
-
|
202
186
|
# This method is used to specify the details of a contained resource.
|
203
187
|
# Pass the name as the first argument and a hash of options as the second argument
|
204
188
|
# Note that this method doesn't actually execute the block, but stores it, to be executed
|
@@ -10,9 +10,9 @@ module ActiveFedora::Associations::Builder
|
|
10
10
|
# configure_dependency
|
11
11
|
def self.build(model, name, options, &block)
|
12
12
|
if model.dangerous_attribute_method?(name)
|
13
|
-
|
13
|
+
raise ArgumentError, "You tried to define an association named #{name} on the model #{model.name}, but " \
|
14
14
|
"this will conflict with a method #{name} already defined by ActiveFedora. " \
|
15
|
-
"Please choose a different association name."
|
15
|
+
"Please choose a different association name."
|
16
16
|
end
|
17
17
|
|
18
18
|
extension = define_extensions model, name, &block
|
@@ -24,12 +24,8 @@ module ActiveFedora::Associations::Builder
|
|
24
24
|
end
|
25
25
|
|
26
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
|
27
|
+
raise ArgumentError, "association names must be a Symbol. You provided #{name.inspect}" unless name.is_a?(Symbol)
|
31
28
|
validate_options(options)
|
32
|
-
translate_property_to_predicate(options)
|
33
29
|
|
34
30
|
scope = build_scope(scope, extension)
|
35
31
|
name = better_name(name)
|
@@ -67,18 +63,6 @@ module ActiveFedora::Associations::Builder
|
|
67
63
|
name
|
68
64
|
end
|
69
65
|
|
70
|
-
def self.translate_property_to_predicate(options)
|
71
|
-
return unless options[:property]
|
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)
|
73
|
-
options[:predicate] = predicate(options.delete(:property))
|
74
|
-
end
|
75
|
-
|
76
|
-
# Returns the RDF predicate as defined by the :property attribute
|
77
|
-
def self.predicate(property)
|
78
|
-
return property if property.is_a? RDF::URI
|
79
|
-
ActiveFedora::Predicates.find_graph_predicate(property)
|
80
|
-
end
|
81
|
-
|
82
66
|
def self.define_extensions(_model, _name)
|
83
67
|
end
|
84
68
|
|
@@ -1,6 +1,5 @@
|
|
1
1
|
module ActiveFedora::Associations::Builder
|
2
2
|
class HasAndBelongsToMany < CollectionAssociation #:nodoc:
|
3
|
-
extend Deprecation
|
4
3
|
def self.macro
|
5
4
|
:has_and_belongs_to_many
|
6
5
|
end
|
@@ -11,8 +10,7 @@ module ActiveFedora::Associations::Builder
|
|
11
10
|
|
12
11
|
def self.validate_options(options)
|
13
12
|
super
|
14
|
-
|
15
|
-
raise "You must specify a predicate for #{name}" unless options[:predicate]
|
13
|
+
raise ArgumentError, "You must specify a predicate for #{name}" unless options[:predicate]
|
16
14
|
raise ArgumentError, "Predicate must be a kind of RDF::URI" unless options[:predicate].is_a?(RDF::URI)
|
17
15
|
end
|
18
16
|
end
|
@@ -1,15 +1,6 @@
|
|
1
|
-
require 'deprecation'
|
2
|
-
|
3
1
|
module ActiveFedora
|
4
2
|
module AttachedFiles
|
5
3
|
extend ActiveSupport::Concern
|
6
|
-
extend Deprecation
|
7
|
-
self.deprecation_horizon = "active-fedora 10.0"
|
8
|
-
|
9
|
-
def ds_specs
|
10
|
-
self.class.child_resource_reflections
|
11
|
-
end
|
12
|
-
deprecation_deprecate :ds_specs
|
13
4
|
|
14
5
|
def serialize_attached_files
|
15
6
|
declared_attached_files.each_value(&:serialize!)
|
@@ -34,20 +25,10 @@ module ActiveFedora
|
|
34
25
|
@attached_files ||= FilesHash.new(self)
|
35
26
|
end
|
36
27
|
|
37
|
-
def datastreams
|
38
|
-
attached_files
|
39
|
-
end
|
40
|
-
deprecation_deprecate :datastreams
|
41
|
-
|
42
28
|
def clear_attached_files
|
43
29
|
@attached_files = nil
|
44
30
|
end
|
45
31
|
|
46
|
-
def clear_datastreams
|
47
|
-
clear_attached_files
|
48
|
-
end
|
49
|
-
deprecation_deprecate :clear_datastreams
|
50
|
-
|
51
32
|
def contains_assertions
|
52
33
|
resource.query(subject: resource, predicate: ::RDF::Vocab::LDP.contains).objects.map(&:to_s)
|
53
34
|
end
|
@@ -71,11 +52,6 @@ module ActiveFedora
|
|
71
52
|
file_path
|
72
53
|
end
|
73
54
|
|
74
|
-
def add_datastream(datastream, opts = {})
|
75
|
-
attach_file(datastream, opts)
|
76
|
-
end
|
77
|
-
deprecation_deprecate :add_datastream
|
78
|
-
|
79
55
|
# @return [Array] all attached files that return true for `metadata?` and are not Rels-ext
|
80
56
|
def metadata_streams
|
81
57
|
attached_files.select { |_k, ds| ds.metadata? }.values
|
@@ -85,11 +61,6 @@ module ActiveFedora
|
|
85
61
|
# File Management
|
86
62
|
#
|
87
63
|
|
88
|
-
def add_file_datastream(file, opts = {})
|
89
|
-
Deprecation.warn AttachedFiles, "add_file_datastream is deprecated and will be removed in active-fedora 10.0. Use add_file instead"
|
90
|
-
add_file(file, opts)
|
91
|
-
end
|
92
|
-
|
93
64
|
# Attach the given stream/string to object
|
94
65
|
#
|
95
66
|
# @param [IO, String] file the file to add
|
@@ -98,27 +69,10 @@ module ActiveFedora
|
|
98
69
|
# @option opts [String] :prefix The path prefix (for auto-generated path)
|
99
70
|
# @option opts [String] :mime_type The Mime-Type of the file
|
100
71
|
# @option opts [String] :original_name The original name of the file (used for Content-Disposition)
|
101
|
-
def add_file(file,
|
102
|
-
opts = if args.size == 1
|
103
|
-
args.first
|
104
|
-
else
|
105
|
-
Deprecation.warn AttachedFiles, "The second option to add_file should be a hash. Passing the file path is deprecated and will be removed in active-fedora 10.0.", caller
|
106
|
-
{ path: args[0], original_name: args[1], mime_type: args[2] }
|
107
|
-
end
|
108
|
-
|
109
|
-
if opts[:dsid]
|
110
|
-
Deprecation.warn AttachedFiles, "The :dsid option to add_file is deprecated and will be removed in active-fedora 10.0. Use :path instead", caller
|
111
|
-
opts[:path] = opts[:dsid]
|
112
|
-
end
|
113
|
-
|
72
|
+
def add_file(file, opts)
|
114
73
|
find_or_create_child_resource(opts[:path], opts[:prefix]).tap do |node|
|
115
74
|
node.content = file
|
116
|
-
node.mime_type =
|
117
|
-
Deprecation.warn AttachedFiles, "The :mimeType option to add_file is deprecated and will be removed in active-fedora 10.0. Use :mime_type instead", caller
|
118
|
-
opts[:mimeType]
|
119
|
-
else
|
120
|
-
opts[:mime_type]
|
121
|
-
end
|
75
|
+
node.mime_type = opts[:mime_type]
|
122
76
|
node.original_name = opts[:original_name]
|
123
77
|
end
|
124
78
|
end
|
@@ -154,65 +108,5 @@ module ActiveFedora
|
|
154
108
|
def accessor_name(file_path)
|
155
109
|
file_path.tr('-', '_')
|
156
110
|
end
|
157
|
-
|
158
|
-
module ClassMethods
|
159
|
-
def ds_specs
|
160
|
-
Deprecation.warn(self, "ds_specs is deprecated and will be removed in ActiveFedora 10.0")
|
161
|
-
child_resource_reflections
|
162
|
-
end
|
163
|
-
|
164
|
-
# This method is used to specify the details of a datastream.
|
165
|
-
# You can pass the name as the first argument and a hash of options as the second argument
|
166
|
-
# or you can pass the :name as a value in the args hash. Either way, name is required.
|
167
|
-
# Note that this method doesn't actually execute the block, but stores it, to be executed
|
168
|
-
# by any the implementation of the datastream(specified as :type)
|
169
|
-
#
|
170
|
-
# @param [Hash] args
|
171
|
-
# @option args [Class] :type The class that will represent this datastream, should extend ``ActiveFedora::File''
|
172
|
-
# @option args [String] :name the handle to refer to this datastream as
|
173
|
-
# @option args [String] :url
|
174
|
-
# @option args [Boolean] :autocreate Always create this datastream on new objects
|
175
|
-
# @yield block executed by some kinds of datastreams
|
176
|
-
def has_metadata(*args, &block)
|
177
|
-
Deprecation.warn(self, "has_metadata is deprecated and will be removed in ActiveFedora 10.0. Use has_subresource instead.")
|
178
|
-
if args.first.is_a? String
|
179
|
-
name = args.first
|
180
|
-
args = args[1] || {}
|
181
|
-
args[:name] = name
|
182
|
-
else
|
183
|
-
args = args.first || {}
|
184
|
-
end
|
185
|
-
name = args.delete(:name)
|
186
|
-
raise ArgumentError, "You must provide a :type property for the datastream '#{name}'" unless args[:type]
|
187
|
-
args[:class_name] = args.delete(:type).to_s
|
188
|
-
has_subresource(name, args, &block)
|
189
|
-
end
|
190
|
-
|
191
|
-
# @overload has_file_datastream(name, args)
|
192
|
-
# Declares a file datastream exists for objects of this type
|
193
|
-
# @param [String] name
|
194
|
-
# @param [Hash] args
|
195
|
-
# @option args :type (ActiveFedora::File) The class the datastream should have
|
196
|
-
# @option args [Boolean] :autocreate Always create this datastream on new objects
|
197
|
-
# @overload has_file_datastream(args)
|
198
|
-
# Declares a file datastream exists for objects of this type
|
199
|
-
# @param [Hash] args
|
200
|
-
# @option args :name ("content") The dsid of the datastream
|
201
|
-
# @option args :type (ActiveFedora::File) The class the datastream should have
|
202
|
-
# @option args [Boolean] :autocreate Always create this datastream on new objects
|
203
|
-
def has_file_datastream(*args)
|
204
|
-
Deprecation.warn(self, "has_file_datastream is deprecated and will be removed in ActiveFedora 10.0. Use has_subresource instead.")
|
205
|
-
if args.first.is_a? String
|
206
|
-
name = args.first
|
207
|
-
args = args[1] || {}
|
208
|
-
args[:name] = name
|
209
|
-
else
|
210
|
-
args = args.first || {}
|
211
|
-
end
|
212
|
-
name = args.delete(:name)
|
213
|
-
args[:class_name] = args.delete(:type).to_s
|
214
|
-
has_subresource(name, args)
|
215
|
-
end
|
216
|
-
end
|
217
111
|
end
|
218
112
|
end
|
@@ -1,10 +1,7 @@
|
|
1
1
|
require 'active_model/forbidden_attributes_protection'
|
2
|
-
require 'deprecation'
|
3
2
|
module ActiveFedora
|
4
3
|
module Attributes
|
5
4
|
extend ActiveSupport::Concern
|
6
|
-
extend Deprecation
|
7
|
-
self.deprecation_horizon = 'ActiveFedora 10.0'
|
8
5
|
include ActiveModel::Dirty
|
9
6
|
include ActiveModel::ForbiddenAttributesProtection
|
10
7
|
|
@@ -35,8 +32,7 @@ module ActiveFedora
|
|
35
32
|
# Use the generated method so that single value assetions are single
|
36
33
|
send(key)
|
37
34
|
else
|
38
|
-
|
39
|
-
array_reader(key)
|
35
|
+
raise ArgumentError, "Unknown attribute #{key}"
|
40
36
|
end
|
41
37
|
end
|
42
38
|
|
@@ -49,21 +45,10 @@ module ActiveFedora
|
|
49
45
|
# The attribute is stored in the RDF graph for this object
|
50
46
|
send(key.to_s + "=", value)
|
51
47
|
else
|
52
|
-
|
53
|
-
array_setter(key, value)
|
48
|
+
raise ArgumentError, "Unknown attribute #{key}"
|
54
49
|
end
|
55
50
|
end
|
56
51
|
|
57
|
-
# @return [Boolean] true if there is an reader method and it returns a
|
58
|
-
# value different from the new_value.
|
59
|
-
def value_has_changed?(field, new_value)
|
60
|
-
new_value != array_reader(field)
|
61
|
-
end
|
62
|
-
|
63
|
-
def mark_as_changed(field)
|
64
|
-
send("#{field}_will_change!")
|
65
|
-
end
|
66
|
-
|
67
52
|
def local_attributes
|
68
53
|
self.class.local_attributes
|
69
54
|
end
|
@@ -77,27 +62,6 @@ module ActiveFedora
|
|
77
62
|
respond_to_without_attributes?(:attributes) && self.class.delegated_attributes.include?(attr_name)
|
78
63
|
end
|
79
64
|
|
80
|
-
private
|
81
|
-
|
82
|
-
def array_reader(field, *args)
|
83
|
-
raise UnknownAttributeError.new(self, field) unless self.class.delegated_attributes.key?(field)
|
84
|
-
|
85
|
-
val = self.class.delegated_attributes[field].reader(self, *args)
|
86
|
-
self.class.multiple?(field) ? val : val.first
|
87
|
-
end
|
88
|
-
|
89
|
-
def array_setter(field, args)
|
90
|
-
raise UnknownAttributeError.new(self, field) unless self.class.delegated_attributes.key?(field)
|
91
|
-
if self.class.multiple?(field)
|
92
|
-
if args.present? && !args.respond_to?(:each)
|
93
|
-
raise ArgumentError, "You attempted to set the attribute `#{field}' on `#{self.class}' to a scalar value. However, this attribute is declared as being multivalued."
|
94
|
-
end
|
95
|
-
elsif args.respond_to?(:each) # singular
|
96
|
-
raise ArgumentError, "You attempted to set the attribute `#{field}' on `#{self.class}' to an enumerable value. However, this attribute is declared as being singular."
|
97
|
-
end
|
98
|
-
self.class.delegated_attributes[field].writer(self, args)
|
99
|
-
end
|
100
|
-
|
101
65
|
module ClassMethods
|
102
66
|
def attribute_names
|
103
67
|
@attribute_names ||= delegated_attributes.keys + association_attributes - system_attributes
|
@@ -123,11 +87,6 @@ module ActiveFedora
|
|
123
87
|
outgoing_reflections.values.map { |reflection| reflection.foreign_key.to_s }
|
124
88
|
end
|
125
89
|
|
126
|
-
def defined_attributes
|
127
|
-
Deprecation.warn Attributes, "defined_attributes has been renamed to delegated_attributes. defined_attributes will be removed in ActiveFedora 9"
|
128
|
-
delegated_attributes
|
129
|
-
end
|
130
|
-
|
131
90
|
def delegated_attributes
|
132
91
|
@delegated_attributes ||= {}.with_indifferent_access
|
133
92
|
return @delegated_attributes unless superclass.respond_to?(:delegated_attributes) && value = superclass.delegated_attributes
|
@@ -139,15 +98,6 @@ module ActiveFedora
|
|
139
98
|
@delegated_attributes = val
|
140
99
|
end
|
141
100
|
|
142
|
-
def has_attributes(*fields, &block)
|
143
|
-
options = fields.pop
|
144
|
-
delegate_target = options.delete(:datastream)
|
145
|
-
raise ArgumentError, "You must provide a datastream to has_attributes" if delegate_target.blank?
|
146
|
-
|
147
|
-
Deprecation.warn Attributes, "has_attributes is deprecated and will be removed in ActiveFedora 10.0. Consider using the Form pattern to save all related models or directly delegate the properties and save the target separately"
|
148
|
-
define_delegated_accessor(fields, delegate_target, options, &block)
|
149
|
-
end
|
150
|
-
|
151
101
|
# Reveal if the attribute has been declared unique
|
152
102
|
# @param [Symbol] field the field to query
|
153
103
|
# @return [Boolean]
|
@@ -164,14 +114,8 @@ module ActiveFedora
|
|
164
114
|
end
|
165
115
|
|
166
116
|
def property(name, properties = {}, &block)
|
167
|
-
|
168
|
-
|
169
|
-
elsif properties.key?(:delegate_to)
|
170
|
-
Deprecation.warn Attributes, "delegated properties are deprecated and will be removed in ActiveFedora 10.0. Consider using the Form pattern to save all related models or directly delegate the properties and save the target separately"
|
171
|
-
define_delegated_accessor([name], properties.delete(:delegate_to), properties.reverse_merge(multiple: true), &block)
|
172
|
-
else
|
173
|
-
raise "You must provide `:delegate_to' or `:predicate' options to property"
|
174
|
-
end
|
117
|
+
raise ArgumentError, "You must provide a `:predicate' option to property" unless properties.key?(:predicate)
|
118
|
+
define_active_triple_accessor(name, properties, &block)
|
175
119
|
end
|
176
120
|
|
177
121
|
private
|
@@ -187,19 +131,6 @@ module ActiveFedora
|
|
187
131
|
add_attribute_indexing_config(name, &block) if block_given?
|
188
132
|
end
|
189
133
|
|
190
|
-
def define_delegated_accessor(fields, delegate_target, options, &block)
|
191
|
-
define_attribute_methods fields
|
192
|
-
fields.each do |f|
|
193
|
-
klass = datastream_class_for_name(delegate_target)
|
194
|
-
attribute_properties = options.merge(delegate_target: delegate_target, klass: klass)
|
195
|
-
find_or_create_defined_attribute f, attribute_class(klass), attribute_properties
|
196
|
-
|
197
|
-
create_attribute_reader(f, delegate_target, options)
|
198
|
-
create_attribute_setter(f, delegate_target, options)
|
199
|
-
add_attribute_indexing_config(f, &block) if block_given?
|
200
|
-
end
|
201
|
-
end
|
202
|
-
|
203
134
|
def add_attribute_indexing_config(name, &block)
|
204
135
|
index_config[name] ||= ActiveFedora::Indexing::Map::IndexObject.new(name, &block)
|
205
136
|
end
|
@@ -223,33 +154,6 @@ module ActiveFedora
|
|
223
154
|
def find_or_create_defined_attribute(field, klass, args)
|
224
155
|
delegated_attributes[field] ||= klass.new(field, args)
|
225
156
|
end
|
226
|
-
|
227
|
-
# @param [String] dsid the datastream id
|
228
|
-
# @return [Class] the class of the datastream
|
229
|
-
def datastream_class_for_name(dsid)
|
230
|
-
reflection = _reflect_on_association(dsid.to_sym)
|
231
|
-
reflection ? reflection.klass : ActiveFedora::File
|
232
|
-
end
|
233
|
-
|
234
|
-
def create_attribute_reader(field, _dsid, _args)
|
235
|
-
define_method field do |*opts|
|
236
|
-
array_reader(field, *opts)
|
237
|
-
end
|
238
|
-
end
|
239
|
-
|
240
|
-
def create_attribute_setter(field, _dsid, _args)
|
241
|
-
define_method "#{field}=".to_sym do |v|
|
242
|
-
self[field] = v
|
243
|
-
end
|
244
|
-
end
|
245
|
-
|
246
|
-
def attribute_class(klass)
|
247
|
-
if klass < ActiveFedora::RDFDatastream
|
248
|
-
RdfDatastreamAttribute
|
249
|
-
else
|
250
|
-
OmAttribute
|
251
|
-
end
|
252
|
-
end
|
253
157
|
end
|
254
158
|
end
|
255
159
|
end
|