active-fedora 6.8.0 → 7.0.0.pre1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +15 -5
- data/CONTRIBUTING.md +2 -0
- data/Gemfile +0 -2
- data/History.txt +2 -32
- data/README.md +143 -0
- data/Rakefile +5 -7
- data/active-fedora.gemspec +9 -9
- data/gemfiles/rails3.gemfile +11 -0
- data/gemfiles/rails4.gemfile +10 -0
- data/lib/active_fedora.rb +31 -4
- data/lib/active_fedora/association_relation.rb +18 -0
- data/lib/active_fedora/associations.rb +38 -171
- data/lib/active_fedora/associations/association.rb +163 -0
- data/lib/active_fedora/associations/association_scope.rb +39 -0
- data/lib/active_fedora/associations/belongs_to_association.rb +47 -25
- data/lib/active_fedora/associations/builder/association.rb +55 -0
- data/lib/active_fedora/associations/builder/belongs_to.rb +100 -0
- data/lib/active_fedora/associations/builder/collection_association.rb +56 -0
- data/lib/active_fedora/associations/builder/has_and_belongs_to_many.rb +30 -0
- data/lib/active_fedora/associations/builder/has_many.rb +63 -0
- data/lib/active_fedora/associations/builder/singular_association.rb +32 -0
- data/lib/active_fedora/associations/{association_collection.rb → collection_association.rb} +203 -53
- data/lib/active_fedora/associations/collection_proxy.rb +862 -0
- data/lib/active_fedora/associations/has_and_belongs_to_many_association.rb +35 -25
- data/lib/active_fedora/associations/has_many_association.rb +36 -11
- data/lib/active_fedora/associations/singular_association.rb +62 -0
- data/lib/active_fedora/attributes.rb +43 -139
- data/lib/active_fedora/autosave_association.rb +317 -0
- data/lib/active_fedora/base.rb +10 -327
- data/lib/active_fedora/callbacks.rb +1 -3
- data/lib/active_fedora/content_model.rb +16 -0
- data/lib/active_fedora/core.rb +151 -0
- data/lib/active_fedora/datastream_attribute.rb +76 -0
- data/lib/active_fedora/datastream_hash.rb +8 -13
- data/lib/active_fedora/datastreams.rb +39 -26
- data/lib/active_fedora/digital_object.rb +2 -2
- data/lib/active_fedora/fedora_attributes.rb +45 -0
- data/lib/active_fedora/fixture_loader.rb +1 -1
- data/lib/active_fedora/indexing.rb +6 -1
- data/lib/active_fedora/model.rb +0 -17
- data/lib/active_fedora/nested_attributes.rb +2 -2
- data/lib/active_fedora/null_relation.rb +7 -0
- data/lib/active_fedora/om_datastream.rb +3 -4
- data/lib/active_fedora/persistence.rb +41 -29
- data/lib/active_fedora/querying.rb +2 -163
- data/lib/active_fedora/rdf.rb +1 -0
- data/lib/active_fedora/rdf/indexing.rb +67 -0
- data/lib/active_fedora/rdf_datastream.rb +2 -50
- data/lib/active_fedora/rdf_node.rb +12 -7
- data/lib/active_fedora/rdf_node/term_proxy.rb +30 -21
- data/lib/active_fedora/rdfxml_rdf_datastream.rb +1 -1
- data/lib/active_fedora/reflection.rb +163 -20
- data/lib/active_fedora/relation.rb +33 -130
- data/lib/active_fedora/relation/calculations.rb +19 -0
- data/lib/active_fedora/relation/delegation.rb +22 -0
- data/lib/active_fedora/relation/finder_methods.rb +247 -0
- data/lib/active_fedora/relation/merger.rb +22 -0
- data/lib/active_fedora/relation/query_methods.rb +58 -0
- data/lib/active_fedora/relation/spawn_methods.rb +46 -0
- data/lib/active_fedora/relationship_graph.rb +0 -2
- data/lib/active_fedora/rels_ext_datastream.rb +1 -4
- data/lib/active_fedora/rubydora_connection.rb +1 -1
- data/lib/active_fedora/scoping.rb +20 -0
- data/lib/active_fedora/scoping/default.rb +38 -0
- data/lib/active_fedora/scoping/named.rb +32 -0
- data/lib/active_fedora/semantic_node.rb +54 -106
- data/lib/active_fedora/serialization.rb +19 -0
- data/lib/active_fedora/sharding.rb +58 -0
- data/lib/active_fedora/solr_digital_object.rb +15 -5
- data/lib/active_fedora/solr_instance_loader.rb +1 -1
- data/lib/active_fedora/solr_service.rb +1 -1
- data/lib/active_fedora/unsaved_digital_object.rb +6 -4
- data/lib/active_fedora/version.rb +1 -1
- data/lib/tasks/active_fedora.rake +3 -0
- data/lib/tasks/active_fedora_dev.rake +6 -5
- data/spec/config_helper.rb +14 -14
- data/spec/integration/associations_spec.rb +168 -455
- data/spec/integration/attributes_spec.rb +12 -11
- data/spec/integration/auditable_spec.rb +11 -11
- data/spec/integration/autosave_association_spec.rb +25 -0
- data/spec/integration/base_spec.rb +163 -163
- data/spec/integration/belongs_to_association_spec.rb +166 -0
- data/spec/integration/bug_spec.rb +7 -7
- data/spec/integration/collection_association_spec.rb +58 -0
- data/spec/integration/complex_rdf_datastream_spec.rb +88 -88
- data/spec/integration/datastream_collections_spec.rb +69 -69
- data/spec/integration/datastream_spec.rb +43 -43
- data/spec/integration/datastreams_spec.rb +63 -63
- data/spec/integration/delete_all_spec.rb +46 -39
- data/spec/integration/fedora_solr_sync_spec.rb +5 -5
- data/spec/integration/field_to_solr_name_spec.rb +34 -0
- data/spec/integration/full_featured_model_spec.rb +100 -101
- data/spec/integration/has_and_belongs_to_many_associations_spec.rb +341 -0
- data/spec/integration/has_many_associations_spec.rb +172 -24
- data/spec/integration/json_serialization_spec.rb +31 -0
- data/spec/integration/load_from_solr_spec.rb +48 -0
- data/spec/integration/model_spec.rb +35 -40
- data/spec/integration/nested_attribute_spec.rb +42 -43
- data/spec/integration/ntriples_datastream_spec.rb +131 -113
- data/spec/integration/om_datastream_spec.rb +67 -67
- data/spec/integration/persistence_spec.rb +7 -7
- data/spec/integration/rdf_nested_attributes_spec.rb +56 -56
- data/spec/integration/relation_delegation_spec.rb +26 -25
- data/spec/integration/relation_spec.rb +42 -0
- data/spec/integration/rels_ext_datastream_spec.rb +20 -20
- data/spec/integration/scoped_query_spec.rb +61 -51
- data/spec/integration/solr_instance_loader_spec.rb +5 -5
- data/spec/integration/solr_service_spec.rb +46 -46
- data/spec/samples/hydra-mods_article_datastream.rb +334 -334
- data/spec/samples/hydra-rights_metadata_datastream.rb +57 -57
- data/spec/samples/marpa-dc_datastream.rb +17 -17
- data/spec/samples/models/audio_record.rb +16 -16
- data/spec/samples/models/image.rb +2 -2
- data/spec/samples/models/mods_article.rb +5 -5
- data/spec/samples/models/oral_history.rb +18 -18
- data/spec/samples/models/seminar.rb +24 -24
- data/spec/samples/models/seminar_audio_file.rb +17 -17
- data/spec/samples/oral_history_sample_model.rb +21 -21
- data/spec/samples/special_thing.rb +14 -14
- data/spec/spec_helper.rb +11 -7
- data/spec/support/an_active_model.rb +2 -8
- data/spec/support/freeze_mocks.rb +12 -0
- data/spec/support/mock_fedora.rb +17 -16
- data/spec/unit/active_fedora_spec.rb +58 -60
- data/spec/unit/attributes_spec.rb +314 -0
- data/spec/unit/base_active_model_spec.rb +28 -27
- data/spec/unit/base_cma_spec.rb +5 -5
- data/spec/unit/base_datastream_management_spec.rb +27 -27
- data/spec/unit/base_extra_spec.rb +76 -48
- data/spec/unit/base_spec.rb +277 -348
- data/spec/unit/callback_spec.rb +18 -19
- data/spec/unit/code_configurator_spec.rb +17 -17
- data/spec/unit/config_spec.rb +8 -16
- data/spec/unit/content_model_spec.rb +79 -60
- data/spec/unit/datastream_collections_spec.rb +229 -229
- data/spec/unit/datastream_spec.rb +51 -63
- data/spec/unit/datastreams_spec.rb +87 -87
- data/spec/unit/file_configurator_spec.rb +217 -217
- data/spec/unit/has_and_belongs_to_many_collection_spec.rb +44 -25
- data/spec/unit/has_many_collection_spec.rb +26 -8
- data/spec/unit/inheritance_spec.rb +13 -12
- data/spec/unit/model_spec.rb +39 -45
- data/spec/unit/nom_datastream_spec.rb +15 -15
- data/spec/unit/ntriples_datastream_spec.rb +123 -118
- data/spec/unit/om_datastream_spec.rb +227 -233
- data/spec/unit/persistence_spec.rb +34 -15
- data/spec/unit/predicates_spec.rb +73 -73
- data/spec/unit/property_spec.rb +17 -9
- data/spec/unit/qualified_dublin_core_datastream_spec.rb +33 -33
- data/spec/unit/query_spec.rb +222 -198
- data/spec/unit/rdf_datastream_spec.rb +21 -28
- data/spec/unit/rdf_list_nested_attributes_spec.rb +34 -34
- data/spec/unit/rdf_list_spec.rb +65 -64
- data/spec/unit/rdf_node_spec.rb +7 -7
- data/spec/unit/rdf_xml_writer_spec.rb +10 -10
- data/spec/unit/rdfxml_rdf_datastream_spec.rb +27 -27
- data/spec/unit/relationship_graph_spec.rb +51 -51
- data/spec/unit/rels_ext_datastream_spec.rb +68 -74
- data/spec/unit/rspec_matchers/belong_to_associated_active_fedora_object_matcher_spec.rb +15 -15
- data/spec/unit/rspec_matchers/have_many_associated_active_fedora_objects_matcher_spec.rb +15 -15
- data/spec/unit/rspec_matchers/have_predicate_matcher_spec.rb +15 -15
- data/spec/unit/rspec_matchers/match_fedora_datastream_matcher_spec.rb +12 -12
- data/spec/unit/rubydora_connection_spec.rb +5 -5
- data/spec/unit/semantic_node_spec.rb +48 -107
- data/spec/unit/serializers_spec.rb +4 -4
- data/spec/unit/service_definitions_spec.rb +26 -26
- data/spec/unit/simple_datastream_spec.rb +17 -17
- data/spec/unit/solr_config_options_spec.rb +29 -28
- data/spec/unit/solr_digital_object_spec.rb +17 -25
- data/spec/unit/solr_service_spec.rb +95 -82
- data/spec/unit/unsaved_digital_object_spec.rb +24 -23
- data/spec/unit/validations_spec.rb +21 -21
- metadata +110 -159
- data/.rspec +0 -1
- data/.rubocop.yml +0 -1
- data/.rubocop_todo.yml +0 -938
- data/CONSOLE_GETTING_STARTED.textile +0 -1
- data/NOKOGIRI_DATASTREAMS.textile +0 -1
- data/README.textile +0 -116
- data/lib/active_fedora/associations/association_proxy.rb +0 -178
- data/lib/active_fedora/delegating.rb +0 -72
- data/lib/active_fedora/nokogiri_datastream.rb +0 -11
- data/spec/integration/delegating_spec.rb +0 -59
- data/spec/rails3_test_app/.gitignore +0 -4
- data/spec/rails3_test_app/.rspec +0 -1
- data/spec/rails3_test_app/Gemfile +0 -40
- data/spec/rails3_test_app/Rakefile +0 -7
- data/spec/rails3_test_app/app/controllers/application_controller.rb +0 -3
- data/spec/rails3_test_app/app/helpers/application_helper.rb +0 -2
- data/spec/rails3_test_app/app/views/layouts/application.html.erb +0 -14
- data/spec/rails3_test_app/config.ru +0 -4
- data/spec/rails3_test_app/config/application.rb +0 -42
- data/spec/rails3_test_app/config/boot.rb +0 -6
- data/spec/rails3_test_app/config/database.yml +0 -22
- data/spec/rails3_test_app/config/environment.rb +0 -5
- data/spec/rails3_test_app/config/environments/development.rb +0 -25
- data/spec/rails3_test_app/config/environments/production.rb +0 -49
- data/spec/rails3_test_app/config/environments/test.rb +0 -35
- data/spec/rails3_test_app/config/initializers/backtrace_silencers.rb +0 -7
- data/spec/rails3_test_app/config/initializers/inflections.rb +0 -10
- data/spec/rails3_test_app/config/initializers/mime_types.rb +0 -5
- data/spec/rails3_test_app/config/initializers/secret_token.rb +0 -7
- data/spec/rails3_test_app/config/initializers/session_store.rb +0 -8
- data/spec/rails3_test_app/config/locales/en.yml +0 -5
- data/spec/rails3_test_app/config/routes.rb +0 -58
- data/spec/rails3_test_app/db/seeds.rb +0 -7
- data/spec/rails3_test_app/run_tests +0 -3
- data/spec/rails3_test_app/script/rails +0 -6
- data/spec/rails3_test_app/spec/spec_helper.rb +0 -27
- data/spec/rails3_test_app/spec/unit/rails_3_init.rb +0 -15
- data/spec/unit/association_proxy_spec.rb +0 -12
- data/spec/unit/base_delegate_spec.rb +0 -197
- data/spec/unit/base_delegate_to_spec.rb +0 -73
@@ -1 +0,0 @@
|
|
1
|
-
Moved to "https://github.com/projecthydra/active_fedora/wiki/Getting-Started:-Console-Tour":https://github.com/projecthydra/active_fedora/wiki/Getting-Started:-Console-Tour
|
@@ -1 +0,0 @@
|
|
1
|
-
Moved to "https://github.com/projecthydra/active_fedora/wiki/Nokogiri-Datastreams":https://github.com/projecthydra/active_fedora/wiki/Nokogiri-Datastreams
|
data/README.textile
DELETED
@@ -1,116 +0,0 @@
|
|
1
|
-
h2. Description
|
2
|
-
|
3
|
-
!https://travis-ci.org/projecthydra/active_fedora.png?branch=master!:https://travis-ci.org/projecthydra/active_fedora !https://badge.fury.io/rb/active-fedora.png!:http://badge.fury.io/rb/active-fedora !https://gemnasium.com/projecthydra/active_fedora.png!:https://gemnasium.com/projecthydra/active_fedora
|
4
|
-
|
5
|
-
|
6
|
-
RubyFedora and ActiveFedora provide a set of Ruby gems for creating and managing objects in the Fedora Repository Architecture ("http://fedora-commons.org":http://fedora-commons.org). ActiveFedora is loosely based on "ActiveRecord" in Rails. The 3.x series of ActiveFedora depends on Rails 3, specifically activemodel and activesupport.
|
7
|
-
|
8
|
-
h2. Getting Help
|
9
|
-
|
10
|
-
* Community Discussions & Mailing List are located at "http://groups.google.com/group/active-fedora":http://groups.google.com/group/active-fedora
|
11
|
-
* Developers hang out on IRC in #projecthydra on freenet.
|
12
|
-
|
13
|
-
h2. Installation
|
14
|
-
|
15
|
-
The gem is hosted on gemcutter.
|
16
|
-
|
17
|
-
<pre>gem install active-fedora</pre>
|
18
|
-
|
19
|
-
h2. Getting Started
|
20
|
-
|
21
|
-
The "ActiveFedora Console Tour":https://github.com/projecthydra/active_fedora/wiki/Getting-Started:-Console-Tour gives you a brief tour through ActiveFedora's features on the command line.
|
22
|
-
|
23
|
-
h2. Generators
|
24
|
-
|
25
|
-
You can generate a model inheriting from ActiveFedora::Base.
|
26
|
-
|
27
|
-
<pre>rails generate active_fedora:model Book</pre>
|
28
|
-
|
29
|
-
h2. Testing (this Gem)
|
30
|
-
|
31
|
-
In order to run the RSpec tests, you need to have a copy of the ActiveFedora source code, and then run bundle install in the source directory. Testing requires hydra-jetty, which contains version for Fedora and Solr. Setting up and maintaining hydra-jetty for the purposes of testing this gem is all accomplished via
|
32
|
-
|
33
|
-
<pre>
|
34
|
-
git clone https://github.com/projecthydra/active_fedora.git
|
35
|
-
cd /wherever/active_fedora/is
|
36
|
-
bundle install
|
37
|
-
</pre>
|
38
|
-
|
39
|
-
h3. Using the continuous integration server
|
40
|
-
|
41
|
-
You can test ActiveFedora using the same process as our continuous integration server. To do that, unzip a copy
|
42
|
-
of hydra-jetty first. This includes copies of Fedora and Solr which are used during the testing process.
|
43
|
-
|
44
|
-
<pre>
|
45
|
-
rake jetty:unzip
|
46
|
-
</pre>
|
47
|
-
|
48
|
-
Once hydra-jetty is unzipped, the ci rake task will spin up jetty, import the fixtures, and run the tests for you.
|
49
|
-
|
50
|
-
<pre>
|
51
|
-
rake active_fedora:ci
|
52
|
-
</pre>
|
53
|
-
|
54
|
-
h3. Testing Manually
|
55
|
-
|
56
|
-
If you want to run the tests manually, follow these instructions.
|
57
|
-
|
58
|
-
You need to have a copy of hydra-jetty running. To do this, download a working copy of "hydra-jetty":https://github.com/projecthydra/hydra-jetty, cd into its root and run
|
59
|
-
|
60
|
-
<pre>
|
61
|
-
java -jar start.jar
|
62
|
-
</pre>
|
63
|
-
|
64
|
-
Now you're ready to run the tests. In the directory where active_fedora is installed, run
|
65
|
-
|
66
|
-
<pre>
|
67
|
-
rake spec
|
68
|
-
</pre>
|
69
|
-
|
70
|
-
h2. Predicate Mappings
|
71
|
-
|
72
|
-
ActiveFedora versions 2.2.1 and higher provides specialized control over the predicate mappings used by SemanticNode. In order to provide your own mappings,
|
73
|
-
you must supply a predicate_mappings.yml in the same format as the config/predicate_mappings.yml file shipped with the ActiveFedora gem. Place the file in the same directory
|
74
|
-
as your fedora.yml file and use the current method of initializing ActiveFedora:
|
75
|
-
|
76
|
-
<pre>
|
77
|
-
ActiveFedora.init("/path/to/my/config/fedora.yml")
|
78
|
-
</pre>
|
79
|
-
|
80
|
-
If no predicate_mappings.yml file is found, ActiveFedora will use the default mappings.
|
81
|
-
|
82
|
-
h2. Acknowledgements
|
83
|
-
|
84
|
-
Creator: Matt Zumwalt ("MediaShelf":http://yourmediashelf.com)
|
85
|
-
|
86
|
-
Developers:
|
87
|
-
Justin Coyne, McClain Looney & Eddie Shin ("MediaShelf":http://yourmediashelf.com), Rick Johnson (Notre Dame)
|
88
|
-
|
89
|
-
h2. LICENSE:
|
90
|
-
|
91
|
-
Copyright (c) 2009-2012 Matt Zumwalt & MediaShelf, LLC
|
92
|
-
|
93
|
-
This program is free software: you can redistribute it and/or modify
|
94
|
-
it under the terms of the GNU Lesser General Public License (LGPL) as
|
95
|
-
published by the Free Software Foundation, either version 3 of the License,
|
96
|
-
or (at your option) any later version.
|
97
|
-
|
98
|
-
This program is distributed in the hope that it will be useful,
|
99
|
-
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
100
|
-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
101
|
-
GNU General Public License for more details.
|
102
|
-
|
103
|
-
You should have received a copy of the GNU Lesser General Public License
|
104
|
-
along with this program. If not, see <http://www.gnu.org/licenses/> or
|
105
|
-
see <http://www.gnu.org/licenses/lgpl.html>.
|
106
|
-
|
107
|
-
The above copyright notice and this permission notice shall be
|
108
|
-
included in all copies or substantial portions of the Software.
|
109
|
-
|
110
|
-
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
111
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
112
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
113
|
-
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
114
|
-
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
115
|
-
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
116
|
-
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -1,178 +0,0 @@
|
|
1
|
-
module ActiveFedora
|
2
|
-
module Associations
|
3
|
-
# This is the root class of all association proxies:
|
4
|
-
#
|
5
|
-
# AssociationProxy
|
6
|
-
# BelongsToAssociation
|
7
|
-
# AssociationCollection
|
8
|
-
# HasManyAssociation
|
9
|
-
#
|
10
|
-
# Association proxies in Active Fedora are middlemen between the object that
|
11
|
-
# holds the association, known as the <tt>@owner</tt>, and the actual associated
|
12
|
-
# object, known as the <tt>@target</tt>. The kind of association any proxy is
|
13
|
-
# about is available in <tt>@reflection</tt>. That's an instance of the class
|
14
|
-
# ActiveFedora::Reflection::AssociationReflection.
|
15
|
-
#
|
16
|
-
# For example, given
|
17
|
-
#
|
18
|
-
# class Blog < ActiveFedora::Base
|
19
|
-
# has_many :posts
|
20
|
-
# end
|
21
|
-
#
|
22
|
-
# blog = Blog.find('changeme:123')
|
23
|
-
#
|
24
|
-
# the association proxy in <tt>blog.posts</tt> has the object in +blog+ as
|
25
|
-
# <tt>@owner</tt>, the collection of its posts as <tt>@target</tt>, and
|
26
|
-
# the <tt>@reflection</tt> object represents a <tt>:has_many</tt> macro.
|
27
|
-
#
|
28
|
-
# This class has most of the basic instance methods removed, and delegates
|
29
|
-
# unknown methods to <tt>@target</tt> via <tt>method_missing</tt>. As a
|
30
|
-
# corner case, it even removes the +class+ method and that's why you get
|
31
|
-
#
|
32
|
-
# blog.posts.class # => Array
|
33
|
-
#
|
34
|
-
# though the object behind <tt>blog.posts</tt> is not an Array, but an
|
35
|
-
# ActiveFedora::Associations::HasManyAssociation.
|
36
|
-
|
37
|
-
class AssociationProxy
|
38
|
-
#delegate :to_param, :to=>:target
|
39
|
-
instance_methods.each { |m| undef_method m unless m.to_s =~ /^(?:nil\?|send|object_id|to_a)$|^__|^respond_to|proxy_/ }
|
40
|
-
|
41
|
-
def initialize(owner, reflection)
|
42
|
-
@owner, @reflection = owner, reflection
|
43
|
-
@updated = false
|
44
|
-
# reflection.check_validity!
|
45
|
-
# Array.wrap(reflection.options[:extend]).each { |ext| proxy_extend(ext) }
|
46
|
-
reset
|
47
|
-
end
|
48
|
-
|
49
|
-
# Resets the \loaded flag to +false+ and sets the \target to +nil+.
|
50
|
-
def reset
|
51
|
-
@loaded = false
|
52
|
-
@target = nil
|
53
|
-
end
|
54
|
-
|
55
|
-
# Reloads the \target and returns +self+ on success.
|
56
|
-
def reload
|
57
|
-
reset
|
58
|
-
load_target
|
59
|
-
self unless @target.nil?
|
60
|
-
end
|
61
|
-
|
62
|
-
# Has the \target been already \loaded?
|
63
|
-
def loaded?
|
64
|
-
@loaded
|
65
|
-
end
|
66
|
-
|
67
|
-
# Asserts the \target has been loaded setting the \loaded flag to +true+.
|
68
|
-
def loaded
|
69
|
-
@loaded = true
|
70
|
-
end
|
71
|
-
|
72
|
-
# Returns the target of this proxy, same as +proxy_target+.
|
73
|
-
def target
|
74
|
-
@target
|
75
|
-
end
|
76
|
-
|
77
|
-
# Sets the target of this proxy to <tt>\target</tt>, and the \loaded flag to +true+.
|
78
|
-
def target=(target)
|
79
|
-
@target = target
|
80
|
-
loaded
|
81
|
-
end
|
82
|
-
|
83
|
-
# # Forwards the call to the target. Loads the \target if needed.
|
84
|
-
# def inspect
|
85
|
-
# load_target
|
86
|
-
# @target.inspect
|
87
|
-
# end
|
88
|
-
|
89
|
-
protected
|
90
|
-
|
91
|
-
|
92
|
-
# Assigns the ID of the owner to the corresponding foreign key in +record+.
|
93
|
-
# If the association is polymorphic the type of the owner is also set.
|
94
|
-
def set_belongs_to_association_for(record)
|
95
|
-
unless @owner.new_record?
|
96
|
-
record.add_relationship(@reflection.options[:property], @owner)
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
|
101
|
-
private
|
102
|
-
def method_missing(method, *args)
|
103
|
-
if load_target
|
104
|
-
unless @target.respond_to?(method)
|
105
|
-
message = "undefined method `#{method.to_s}' for \"#{@target}\":#{@target.class.to_s}"
|
106
|
-
raise NoMethodError, message
|
107
|
-
end
|
108
|
-
|
109
|
-
if block_given?
|
110
|
-
@target.send(method, *args) { |*block_args| yield(*block_args) }
|
111
|
-
else
|
112
|
-
@target.send(method, *args)
|
113
|
-
end
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
|
118
|
-
# Loads the \target if needed and returns it.
|
119
|
-
#
|
120
|
-
# This method is abstract in the sense that it relies on +find_target+,
|
121
|
-
# which is expected to be provided by descendants.
|
122
|
-
#
|
123
|
-
# If the \target is already \loaded it is just returned. Thus, you can call
|
124
|
-
# +load_target+ unconditionally to get the \target.
|
125
|
-
#
|
126
|
-
# ActiveFedora::ObjectNotFoundError is rescued within the method, and it is
|
127
|
-
# not reraised. The proxy is \reset and +nil+ is the return value.
|
128
|
-
def load_target
|
129
|
-
return nil unless defined?(@loaded)
|
130
|
-
|
131
|
-
if !loaded? and (!@owner.new_record? || foreign_key_present)
|
132
|
-
@target = find_target
|
133
|
-
end
|
134
|
-
|
135
|
-
if @target.nil?
|
136
|
-
reset
|
137
|
-
else
|
138
|
-
@loaded = true
|
139
|
-
@target
|
140
|
-
end
|
141
|
-
end
|
142
|
-
|
143
|
-
# Can be overwritten by associations that might have the foreign key
|
144
|
-
# available for an association without having the object itself (and
|
145
|
-
# still being a new record). Currently, only +belongs_to+ presents
|
146
|
-
# this scenario.
|
147
|
-
def foreign_key_present
|
148
|
-
false
|
149
|
-
end
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
# Raises ActiveFedora::AssociationTypeMismatch unless +record+ is of
|
154
|
-
# the kind of the class of the associated objects. Meant to be used as
|
155
|
-
# a sanity check when you are about to assign an associated record.
|
156
|
-
def raise_on_type_mismatch(record)
|
157
|
-
unless record.is_a?(@reflection.klass) || record.is_a?(@reflection.class_name.constantize)
|
158
|
-
message = "#{@reflection.class_name}(##{@reflection.klass.object_id}) expected, got #{record.class}(##{record.class.object_id})"
|
159
|
-
raise ActiveFedora::AssociationTypeMismatch, message
|
160
|
-
end
|
161
|
-
end
|
162
|
-
|
163
|
-
|
164
|
-
if RUBY_VERSION < '1.9.2'
|
165
|
-
# Array#flatten has problems with recursive arrays before Ruby 1.9.2.
|
166
|
-
# Going one level deeper solves the majority of the problems.
|
167
|
-
def flatten_deeper(array)
|
168
|
-
array.collect { |element| (element.respond_to?(:flatten) && !element.is_a?(Hash)) ? element.flatten : element }.flatten
|
169
|
-
end
|
170
|
-
else
|
171
|
-
def flatten_deeper(array)
|
172
|
-
array.flatten
|
173
|
-
end
|
174
|
-
end
|
175
|
-
|
176
|
-
end
|
177
|
-
end
|
178
|
-
end
|
@@ -1,72 +0,0 @@
|
|
1
|
-
module ActiveFedora
|
2
|
-
module Delegating
|
3
|
-
extend ActiveSupport::Concern
|
4
|
-
extend Deprecation
|
5
|
-
module ClassMethods
|
6
|
-
# Provides a delegate class method to expose methods in metadata streams
|
7
|
-
# as member of the base object. Pass the target datastream via the
|
8
|
-
# <tt>:to</tt> argument. If you want to return a multivalue result, (e.g. array
|
9
|
-
# instead of a string) set the <tt>:multiple</tt> argument to true.
|
10
|
-
#
|
11
|
-
# The optional <tt>:at</tt> argument provides a terminology that the delegate will point to.
|
12
|
-
#
|
13
|
-
# class Foo < ActiveFedora::Base
|
14
|
-
# has_metadata :name => "descMetadata", :type => MyDatastream
|
15
|
-
#
|
16
|
-
# delegate :field1, :to=>"descMetadata", multiple: false
|
17
|
-
# delegate :field2, :to=>"descMetadata", :at=>[:term1, :term2], multiple: true
|
18
|
-
# end
|
19
|
-
#
|
20
|
-
# foo = Foo.new
|
21
|
-
# foo.field1 = "My Value"
|
22
|
-
# foo.field1 # => "My Value"
|
23
|
-
# foo.field2 # => [""]
|
24
|
-
# foo.field3 # => NoMethodError: undefined method `field3' for #<Foo:0x1af30c>
|
25
|
-
#
|
26
|
-
# The optional <tt>:default</tt> forces this method to have the behavior defined by ActiveSupport
|
27
|
-
# until this method has a chance to be removed
|
28
|
-
#
|
29
|
-
# delegate :method1, to: 'descMetadata', default: true
|
30
|
-
|
31
|
-
def delegate(*methods)
|
32
|
-
fields = methods.dup
|
33
|
-
options = fields.pop
|
34
|
-
unless options.is_a?(Hash) && to = options[:to]
|
35
|
-
raise ArgumentError, "Target is required"
|
36
|
-
end
|
37
|
-
if ds_specs.has_key?(to.to_s) && !options[:default]
|
38
|
-
Deprecation.warn(Delegating, "delegate is deprecated and will be removed in ActiveFedora 7.0. use has_attributes instead", caller(1))
|
39
|
-
datastream = options.delete(:to)
|
40
|
-
has_attributes fields.first, options.merge!({:datastream=>datastream})
|
41
|
-
else
|
42
|
-
super(*methods)
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
# Allows you to delegate multiple terminologies to the same datastream, instead
|
47
|
-
# having to call the method each time for each term. The target datastream is the
|
48
|
-
# first argument, followed by an array of the terms that will point to that
|
49
|
-
# datastream. Terms must be a single value, ie. :field and not [:term1, :term2].
|
50
|
-
# This is best accomplished by refining your OM terminology using :ref or :proxy
|
51
|
-
# methods to reduce nested terms down to one.
|
52
|
-
#
|
53
|
-
# class Foo < ActiveFedora::Base
|
54
|
-
# has_metadata :name => "descMetadata", :type => MyDatastream
|
55
|
-
#
|
56
|
-
# delegate_to :descMetadata, [:field1, :field2]
|
57
|
-
# end
|
58
|
-
#
|
59
|
-
# foo = Foo.new
|
60
|
-
# foo.field1 = "My Value"
|
61
|
-
# foo.field1 # => "My Value"
|
62
|
-
# foo.field2 # => [""]
|
63
|
-
# foo.field3 # => NoMethodError: undefined method `field3' for #<Foo:0x1af30c>
|
64
|
-
|
65
|
-
def delegate_to(datastream,fields,args={})
|
66
|
-
Deprecation.warn(Delegating, "delegate_to is deprecated and will be removed in ActiveFedora 7.0. use has_attributes instead", caller(1))
|
67
|
-
has_attributes *fields, args.merge!({:datastream=>datastream})
|
68
|
-
end
|
69
|
-
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
@@ -1,11 +0,0 @@
|
|
1
|
-
#this class represents a xml metadata datastream
|
2
|
-
module ActiveFedora
|
3
|
-
class NokogiriDatastream < OmDatastream
|
4
|
-
extend Deprecation
|
5
|
-
def initialize(digital_object=nil, dsid=nil, options={})
|
6
|
-
Deprecation.warn(self.class, "NokogiriDatastream is deprecated and will be removed in hydra-head 7.0. Use OmDatastream insead.", caller(2))
|
7
|
-
super
|
8
|
-
end
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
@@ -1,59 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe 'delegating properties' do
|
4
|
-
describe 'that have a reader and writer' do
|
5
|
-
before :all do
|
6
|
-
class TitledObject < ActiveFedora::Base
|
7
|
-
has_metadata 'foo', type: ActiveFedora::SimpleDatastream do |m|
|
8
|
-
m.field 'title', :string
|
9
|
-
end
|
10
|
-
delegate :title, to: 'foo', multiple: false
|
11
|
-
end
|
12
|
-
end
|
13
|
-
after :all do
|
14
|
-
Object.send(:remove_const, :TitledObject)
|
15
|
-
end
|
16
|
-
|
17
|
-
describe 'save' do
|
18
|
-
subject do
|
19
|
-
obj = TitledObject.create
|
20
|
-
obj.title = 'Hydra for Dummies'
|
21
|
-
obj.save
|
22
|
-
obj
|
23
|
-
end
|
24
|
-
it 'should keep a list of changes after a successful save' do
|
25
|
-
expect(subject.previous_changes).not_to be_empty
|
26
|
-
expect(subject.previous_changes.keys).to include('title')
|
27
|
-
end
|
28
|
-
it 'should clean out changes' do
|
29
|
-
expect(subject.title_changed?).to be_falsey
|
30
|
-
expect(subject.changes).to be_empty
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
describe 'that only have a writer' do
|
36
|
-
before :all do
|
37
|
-
class TestDatastream < ActiveFedora::NtriplesRDFDatastream
|
38
|
-
# accepts_nested_attributes_for :title, would generate a method like this:
|
39
|
-
def title_attributes=(attributes)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
class TitledObject < ActiveFedora::Base
|
43
|
-
has_metadata 'foo', type: TestDatastream
|
44
|
-
delegate :title_attributes, to: 'foo', multiple: false
|
45
|
-
end
|
46
|
-
end
|
47
|
-
after :all do
|
48
|
-
Object.send(:remove_const, :TitledObject)
|
49
|
-
Object.send(:remove_const, :TestDatastream)
|
50
|
-
end
|
51
|
-
|
52
|
-
subject { TitledObject.new }
|
53
|
-
|
54
|
-
it 'Should delegate the method' do
|
55
|
-
subject.title_attributes = {'0' => {'title' => 'Hello'}}
|
56
|
-
end
|
57
|
-
|
58
|
-
end
|
59
|
-
end
|