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.
Files changed (215) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.travis.yml +15 -5
  4. data/CONTRIBUTING.md +2 -0
  5. data/Gemfile +0 -2
  6. data/History.txt +2 -32
  7. data/README.md +143 -0
  8. data/Rakefile +5 -7
  9. data/active-fedora.gemspec +9 -9
  10. data/gemfiles/rails3.gemfile +11 -0
  11. data/gemfiles/rails4.gemfile +10 -0
  12. data/lib/active_fedora.rb +31 -4
  13. data/lib/active_fedora/association_relation.rb +18 -0
  14. data/lib/active_fedora/associations.rb +38 -171
  15. data/lib/active_fedora/associations/association.rb +163 -0
  16. data/lib/active_fedora/associations/association_scope.rb +39 -0
  17. data/lib/active_fedora/associations/belongs_to_association.rb +47 -25
  18. data/lib/active_fedora/associations/builder/association.rb +55 -0
  19. data/lib/active_fedora/associations/builder/belongs_to.rb +100 -0
  20. data/lib/active_fedora/associations/builder/collection_association.rb +56 -0
  21. data/lib/active_fedora/associations/builder/has_and_belongs_to_many.rb +30 -0
  22. data/lib/active_fedora/associations/builder/has_many.rb +63 -0
  23. data/lib/active_fedora/associations/builder/singular_association.rb +32 -0
  24. data/lib/active_fedora/associations/{association_collection.rb → collection_association.rb} +203 -53
  25. data/lib/active_fedora/associations/collection_proxy.rb +862 -0
  26. data/lib/active_fedora/associations/has_and_belongs_to_many_association.rb +35 -25
  27. data/lib/active_fedora/associations/has_many_association.rb +36 -11
  28. data/lib/active_fedora/associations/singular_association.rb +62 -0
  29. data/lib/active_fedora/attributes.rb +43 -139
  30. data/lib/active_fedora/autosave_association.rb +317 -0
  31. data/lib/active_fedora/base.rb +10 -327
  32. data/lib/active_fedora/callbacks.rb +1 -3
  33. data/lib/active_fedora/content_model.rb +16 -0
  34. data/lib/active_fedora/core.rb +151 -0
  35. data/lib/active_fedora/datastream_attribute.rb +76 -0
  36. data/lib/active_fedora/datastream_hash.rb +8 -13
  37. data/lib/active_fedora/datastreams.rb +39 -26
  38. data/lib/active_fedora/digital_object.rb +2 -2
  39. data/lib/active_fedora/fedora_attributes.rb +45 -0
  40. data/lib/active_fedora/fixture_loader.rb +1 -1
  41. data/lib/active_fedora/indexing.rb +6 -1
  42. data/lib/active_fedora/model.rb +0 -17
  43. data/lib/active_fedora/nested_attributes.rb +2 -2
  44. data/lib/active_fedora/null_relation.rb +7 -0
  45. data/lib/active_fedora/om_datastream.rb +3 -4
  46. data/lib/active_fedora/persistence.rb +41 -29
  47. data/lib/active_fedora/querying.rb +2 -163
  48. data/lib/active_fedora/rdf.rb +1 -0
  49. data/lib/active_fedora/rdf/indexing.rb +67 -0
  50. data/lib/active_fedora/rdf_datastream.rb +2 -50
  51. data/lib/active_fedora/rdf_node.rb +12 -7
  52. data/lib/active_fedora/rdf_node/term_proxy.rb +30 -21
  53. data/lib/active_fedora/rdfxml_rdf_datastream.rb +1 -1
  54. data/lib/active_fedora/reflection.rb +163 -20
  55. data/lib/active_fedora/relation.rb +33 -130
  56. data/lib/active_fedora/relation/calculations.rb +19 -0
  57. data/lib/active_fedora/relation/delegation.rb +22 -0
  58. data/lib/active_fedora/relation/finder_methods.rb +247 -0
  59. data/lib/active_fedora/relation/merger.rb +22 -0
  60. data/lib/active_fedora/relation/query_methods.rb +58 -0
  61. data/lib/active_fedora/relation/spawn_methods.rb +46 -0
  62. data/lib/active_fedora/relationship_graph.rb +0 -2
  63. data/lib/active_fedora/rels_ext_datastream.rb +1 -4
  64. data/lib/active_fedora/rubydora_connection.rb +1 -1
  65. data/lib/active_fedora/scoping.rb +20 -0
  66. data/lib/active_fedora/scoping/default.rb +38 -0
  67. data/lib/active_fedora/scoping/named.rb +32 -0
  68. data/lib/active_fedora/semantic_node.rb +54 -106
  69. data/lib/active_fedora/serialization.rb +19 -0
  70. data/lib/active_fedora/sharding.rb +58 -0
  71. data/lib/active_fedora/solr_digital_object.rb +15 -5
  72. data/lib/active_fedora/solr_instance_loader.rb +1 -1
  73. data/lib/active_fedora/solr_service.rb +1 -1
  74. data/lib/active_fedora/unsaved_digital_object.rb +6 -4
  75. data/lib/active_fedora/version.rb +1 -1
  76. data/lib/tasks/active_fedora.rake +3 -0
  77. data/lib/tasks/active_fedora_dev.rake +6 -5
  78. data/spec/config_helper.rb +14 -14
  79. data/spec/integration/associations_spec.rb +168 -455
  80. data/spec/integration/attributes_spec.rb +12 -11
  81. data/spec/integration/auditable_spec.rb +11 -11
  82. data/spec/integration/autosave_association_spec.rb +25 -0
  83. data/spec/integration/base_spec.rb +163 -163
  84. data/spec/integration/belongs_to_association_spec.rb +166 -0
  85. data/spec/integration/bug_spec.rb +7 -7
  86. data/spec/integration/collection_association_spec.rb +58 -0
  87. data/spec/integration/complex_rdf_datastream_spec.rb +88 -88
  88. data/spec/integration/datastream_collections_spec.rb +69 -69
  89. data/spec/integration/datastream_spec.rb +43 -43
  90. data/spec/integration/datastreams_spec.rb +63 -63
  91. data/spec/integration/delete_all_spec.rb +46 -39
  92. data/spec/integration/fedora_solr_sync_spec.rb +5 -5
  93. data/spec/integration/field_to_solr_name_spec.rb +34 -0
  94. data/spec/integration/full_featured_model_spec.rb +100 -101
  95. data/spec/integration/has_and_belongs_to_many_associations_spec.rb +341 -0
  96. data/spec/integration/has_many_associations_spec.rb +172 -24
  97. data/spec/integration/json_serialization_spec.rb +31 -0
  98. data/spec/integration/load_from_solr_spec.rb +48 -0
  99. data/spec/integration/model_spec.rb +35 -40
  100. data/spec/integration/nested_attribute_spec.rb +42 -43
  101. data/spec/integration/ntriples_datastream_spec.rb +131 -113
  102. data/spec/integration/om_datastream_spec.rb +67 -67
  103. data/spec/integration/persistence_spec.rb +7 -7
  104. data/spec/integration/rdf_nested_attributes_spec.rb +56 -56
  105. data/spec/integration/relation_delegation_spec.rb +26 -25
  106. data/spec/integration/relation_spec.rb +42 -0
  107. data/spec/integration/rels_ext_datastream_spec.rb +20 -20
  108. data/spec/integration/scoped_query_spec.rb +61 -51
  109. data/spec/integration/solr_instance_loader_spec.rb +5 -5
  110. data/spec/integration/solr_service_spec.rb +46 -46
  111. data/spec/samples/hydra-mods_article_datastream.rb +334 -334
  112. data/spec/samples/hydra-rights_metadata_datastream.rb +57 -57
  113. data/spec/samples/marpa-dc_datastream.rb +17 -17
  114. data/spec/samples/models/audio_record.rb +16 -16
  115. data/spec/samples/models/image.rb +2 -2
  116. data/spec/samples/models/mods_article.rb +5 -5
  117. data/spec/samples/models/oral_history.rb +18 -18
  118. data/spec/samples/models/seminar.rb +24 -24
  119. data/spec/samples/models/seminar_audio_file.rb +17 -17
  120. data/spec/samples/oral_history_sample_model.rb +21 -21
  121. data/spec/samples/special_thing.rb +14 -14
  122. data/spec/spec_helper.rb +11 -7
  123. data/spec/support/an_active_model.rb +2 -8
  124. data/spec/support/freeze_mocks.rb +12 -0
  125. data/spec/support/mock_fedora.rb +17 -16
  126. data/spec/unit/active_fedora_spec.rb +58 -60
  127. data/spec/unit/attributes_spec.rb +314 -0
  128. data/spec/unit/base_active_model_spec.rb +28 -27
  129. data/spec/unit/base_cma_spec.rb +5 -5
  130. data/spec/unit/base_datastream_management_spec.rb +27 -27
  131. data/spec/unit/base_extra_spec.rb +76 -48
  132. data/spec/unit/base_spec.rb +277 -348
  133. data/spec/unit/callback_spec.rb +18 -19
  134. data/spec/unit/code_configurator_spec.rb +17 -17
  135. data/spec/unit/config_spec.rb +8 -16
  136. data/spec/unit/content_model_spec.rb +79 -60
  137. data/spec/unit/datastream_collections_spec.rb +229 -229
  138. data/spec/unit/datastream_spec.rb +51 -63
  139. data/spec/unit/datastreams_spec.rb +87 -87
  140. data/spec/unit/file_configurator_spec.rb +217 -217
  141. data/spec/unit/has_and_belongs_to_many_collection_spec.rb +44 -25
  142. data/spec/unit/has_many_collection_spec.rb +26 -8
  143. data/spec/unit/inheritance_spec.rb +13 -12
  144. data/spec/unit/model_spec.rb +39 -45
  145. data/spec/unit/nom_datastream_spec.rb +15 -15
  146. data/spec/unit/ntriples_datastream_spec.rb +123 -118
  147. data/spec/unit/om_datastream_spec.rb +227 -233
  148. data/spec/unit/persistence_spec.rb +34 -15
  149. data/spec/unit/predicates_spec.rb +73 -73
  150. data/spec/unit/property_spec.rb +17 -9
  151. data/spec/unit/qualified_dublin_core_datastream_spec.rb +33 -33
  152. data/spec/unit/query_spec.rb +222 -198
  153. data/spec/unit/rdf_datastream_spec.rb +21 -28
  154. data/spec/unit/rdf_list_nested_attributes_spec.rb +34 -34
  155. data/spec/unit/rdf_list_spec.rb +65 -64
  156. data/spec/unit/rdf_node_spec.rb +7 -7
  157. data/spec/unit/rdf_xml_writer_spec.rb +10 -10
  158. data/spec/unit/rdfxml_rdf_datastream_spec.rb +27 -27
  159. data/spec/unit/relationship_graph_spec.rb +51 -51
  160. data/spec/unit/rels_ext_datastream_spec.rb +68 -74
  161. data/spec/unit/rspec_matchers/belong_to_associated_active_fedora_object_matcher_spec.rb +15 -15
  162. data/spec/unit/rspec_matchers/have_many_associated_active_fedora_objects_matcher_spec.rb +15 -15
  163. data/spec/unit/rspec_matchers/have_predicate_matcher_spec.rb +15 -15
  164. data/spec/unit/rspec_matchers/match_fedora_datastream_matcher_spec.rb +12 -12
  165. data/spec/unit/rubydora_connection_spec.rb +5 -5
  166. data/spec/unit/semantic_node_spec.rb +48 -107
  167. data/spec/unit/serializers_spec.rb +4 -4
  168. data/spec/unit/service_definitions_spec.rb +26 -26
  169. data/spec/unit/simple_datastream_spec.rb +17 -17
  170. data/spec/unit/solr_config_options_spec.rb +29 -28
  171. data/spec/unit/solr_digital_object_spec.rb +17 -25
  172. data/spec/unit/solr_service_spec.rb +95 -82
  173. data/spec/unit/unsaved_digital_object_spec.rb +24 -23
  174. data/spec/unit/validations_spec.rb +21 -21
  175. metadata +110 -159
  176. data/.rspec +0 -1
  177. data/.rubocop.yml +0 -1
  178. data/.rubocop_todo.yml +0 -938
  179. data/CONSOLE_GETTING_STARTED.textile +0 -1
  180. data/NOKOGIRI_DATASTREAMS.textile +0 -1
  181. data/README.textile +0 -116
  182. data/lib/active_fedora/associations/association_proxy.rb +0 -178
  183. data/lib/active_fedora/delegating.rb +0 -72
  184. data/lib/active_fedora/nokogiri_datastream.rb +0 -11
  185. data/spec/integration/delegating_spec.rb +0 -59
  186. data/spec/rails3_test_app/.gitignore +0 -4
  187. data/spec/rails3_test_app/.rspec +0 -1
  188. data/spec/rails3_test_app/Gemfile +0 -40
  189. data/spec/rails3_test_app/Rakefile +0 -7
  190. data/spec/rails3_test_app/app/controllers/application_controller.rb +0 -3
  191. data/spec/rails3_test_app/app/helpers/application_helper.rb +0 -2
  192. data/spec/rails3_test_app/app/views/layouts/application.html.erb +0 -14
  193. data/spec/rails3_test_app/config.ru +0 -4
  194. data/spec/rails3_test_app/config/application.rb +0 -42
  195. data/spec/rails3_test_app/config/boot.rb +0 -6
  196. data/spec/rails3_test_app/config/database.yml +0 -22
  197. data/spec/rails3_test_app/config/environment.rb +0 -5
  198. data/spec/rails3_test_app/config/environments/development.rb +0 -25
  199. data/spec/rails3_test_app/config/environments/production.rb +0 -49
  200. data/spec/rails3_test_app/config/environments/test.rb +0 -35
  201. data/spec/rails3_test_app/config/initializers/backtrace_silencers.rb +0 -7
  202. data/spec/rails3_test_app/config/initializers/inflections.rb +0 -10
  203. data/spec/rails3_test_app/config/initializers/mime_types.rb +0 -5
  204. data/spec/rails3_test_app/config/initializers/secret_token.rb +0 -7
  205. data/spec/rails3_test_app/config/initializers/session_store.rb +0 -8
  206. data/spec/rails3_test_app/config/locales/en.yml +0 -5
  207. data/spec/rails3_test_app/config/routes.rb +0 -58
  208. data/spec/rails3_test_app/db/seeds.rb +0 -7
  209. data/spec/rails3_test_app/run_tests +0 -3
  210. data/spec/rails3_test_app/script/rails +0 -6
  211. data/spec/rails3_test_app/spec/spec_helper.rb +0 -27
  212. data/spec/rails3_test_app/spec/unit/rails_3_init.rb +0 -15
  213. data/spec/unit/association_proxy_spec.rb +0 -12
  214. data/spec/unit/base_delegate_spec.rb +0 -197
  215. data/spec/unit/base_delegate_to_spec.rb +0 -73
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 38f3e48a7233ed42a4657aabad91c8b386995d5c
4
- data.tar.gz: be721bf82b5bf9f0e7929c4c7845bdaa335b013b
3
+ metadata.gz: c74522099ed634b608f204bad305da5f8d75cab4
4
+ data.tar.gz: 2e8c34f85de2b43228be92b308bae48dc09743be
5
5
  SHA512:
6
- metadata.gz: 58a454c65dda6893b240992458c025266a4f25a837e0f61eb845bb136ff18baceed7ae2c34dfb60027871908c12de0e825ecc1eaa42c1fd86c051ce9779c4af9
7
- data.tar.gz: 49ae4783ee9f477296b966ad76673d5763efb8492d8472a9fb55b9d63e95e4ad9f3bdf622a66b54ea993425954382d67e3017f5d1f67d734961c52345c42c4d2
6
+ metadata.gz: e860a7bcd89e37df76919459ed159f618de89d3e86a34b8ec47fd05f3471a3be2a252b1639e41f4e8d8e1f799f833e8cb4b4d65351ef866bc461691e362bb619
7
+ data.tar.gz: bf290c42f829451d2858e06c25a283bcbbf5d30b4ea942322ea3d0d984740eb38318d6e5262d5c36da38211386b04bc57bd9b41264c54c0dbd718d81780ff3eb
data/.gitignore CHANGED
@@ -12,3 +12,4 @@ bin
12
12
  .idea
13
13
  .ruby-version
14
14
  .ruby-gemset
15
+ gemfiles/*.gemfile.lock
@@ -1,13 +1,23 @@
1
- sudo: false
2
1
  language: ruby
3
2
  rvm:
4
- - 2.2.5
5
- - 2.3.1
3
+ - 2.1.0
4
+ - 2.0.0
5
+ - 1.9.3
6
+
7
+ matrix:
8
+ allow_failures:
9
+ - rvm: 2.1.0
10
+
11
+
12
+ gemfile:
13
+ - gemfiles/rails3.gemfile
14
+ - gemfiles/rails4.gemfile
6
15
 
7
16
  notifications:
8
17
  irc: "irc.freenode.org#projecthydra"
9
18
 
10
19
  before_install:
11
20
  - gem install bundler
12
-
13
- jdk: oraclejdk8
21
+ env:
22
+ global:
23
+ - NOKOGIRI_USE_SYSTEM_LIBRARIES=true
@@ -78,6 +78,8 @@ You should also add yourself to the `CONTRIBUTORS.md` file in the root of the pr
78
78
 
79
79
  ### Submitting Changes
80
80
 
81
+ [Detailed Walkthrough of One Pull Request per Commit](http://ndlib.github.io/practices/one-commit-per-pull-request/)
82
+
81
83
  * Read the article ["Using Pull Requests"](https://help.github.com/articles/using-pull-requests) on GitHub.
82
84
  * Make sure your branch is up to date with its parent branch (i.e. master)
83
85
  * `git checkout master`
data/Gemfile CHANGED
@@ -10,5 +10,3 @@ group :development, :test do
10
10
  end
11
11
 
12
12
  gem 'jruby-openssl', :platform=> :jruby
13
-
14
- gem 'activemodel', '~> 4.2'
@@ -1,36 +1,6 @@
1
- v6.7.8
2
- Backported changes from master for proper deserialization of ActiveFedora::DatastreamHash (Fixed #439) [Michael B. Klein]
1
+ v7.0.0 Unreleased
3
2
 
4
- v6.7.7
5
- Backported changes from master for rubydora 1.7.1+ compatibility (Fixes #354). Upgraded rubydora to ~> 1.7.4. [David Chandek-Stark]
6
-
7
- v6.7.6
8
- Patch ActiveFedora::SolrDigitalObject for Rubydora 1.7.0 compatibility. [David Chandek-Stark]
9
-
10
- v6.7.5
11
- Support for rubydora 1.7.0 [Justin Coyne]
12
-
13
- v6.7.4
14
- Restrict rdf to ~> 1.1.1.1 because rdf 1.1.2 breaks ActiveFedora [Justin Coyne]
15
-
16
- v6.7.3
17
- Force overwrite the blacklight configuration [Justin Coyne]
18
-
19
- v6.7.2
20
- ConfigGenerator should use a unique method name, not `generate` so that it doesn't cause an infinite loop [Justin Coyne]
21
-
22
- v6.7.1
23
- Force RDF data to be UTF-8 The RDF reader chokes on certain character combinations if the raw data is not encoded UTF-8. See https://github.com/ruby-rdf/rdf/issues/142 Fedora does not store character encoding, so by default they come back as ASCII-8BIT. [Justin Coyne]
24
- Renaming invoke -> generate [Jeremy Friesen]
25
-
26
- v6.7.0
27
- Remove loading of rake tasks because they are already loaded in the railtie [Chris Colvard]
28
- Added has_attributes to replace delegate_to [Justin Coyne]
29
-
30
- v6.6.1
31
- Don't try to track changes on delegates that are not attributes [Justin Coyne]
32
- Alter test so that it's compatible with the solr document produced by om 3.0.4 [Justin Coyne]
33
- Fix test for Fedora 3.7 [Justin Coyne]
3
+ Removed update_indexed_attributes, update_datastream_attributes, get_values_from_datastream
34
4
 
35
5
  v6.6.0
36
6
  Add _destroy method for building nested forms [Justin Coyne]
@@ -0,0 +1,143 @@
1
+ Description
2
+ -----------
3
+
4
+ [![Build Status](https://travis-ci.org/projecthydra/active_fedora.png?branch=master)](https://travis-ci.org/projecthydra/active\_fedora)
5
+ [![Version](https://badge.fury.io/rb/active-fedora.png)](http://badge.fury.io/rb/active-fedora)
6
+ [![Dependencies](https://gemnasium.com/projecthydra/active_fedora.png)](https://gemnasium.com/projecthydra/active\_fedora)
7
+
8
+ RubyFedora and ActiveFedora provide a set of Ruby gems for creating and
9
+ managing objects in the Fedora Repository Architecture
10
+ ([http://fedora-commons.org](http://fedora-commons.org)). ActiveFedora
11
+ is loosely based on “ActiveRecord” in Rails. The 3.x series of
12
+ ActiveFedora depends on Rails 3, specifically activemodel and
13
+ activesupport.
14
+
15
+ Getting Help
16
+ ------------
17
+
18
+ - Community Discussions & Mailing List are located at
19
+ [http://groups.google.com/group/hydra-tech](http://groups.google.com/group/hydra-tech)
20
+ - Developers hang out on IRC in \#projecthydra on freenet.
21
+
22
+ Installation
23
+ ------------
24
+
25
+ The gem is hosted on gemcutter.
26
+
27
+ gem install active-fedora
28
+
29
+ Getting Started
30
+ ---------------
31
+
32
+ The [ActiveFedora Console
33
+ Tour](https://github.com/projecthydra/active_fedora/wiki/Getting-Started:-Console-Tour)
34
+ gives you a brief tour through ActiveFedora’s features on the command
35
+ line.
36
+
37
+ Generators
38
+ ----------
39
+
40
+ You can generate a model inheriting from ActiveFedora::Base.
41
+
42
+ rails generate active_fedora:model Book
43
+
44
+ Testing (this Gem)
45
+ ------------------
46
+
47
+ In order to run the RSpec tests, you need to have a copy of the
48
+ ActiveFedora source code, and then run bundle install in the source
49
+ directory. Testing requires hydra-jetty, which contains version for
50
+ Fedora and Solr. Setting up and maintaining hydra-jetty for the purposes
51
+ of testing this gem is all accomplished via
52
+
53
+ git clone https://github.com/projecthydra/active_fedora.git
54
+ cd /wherever/active_fedora/is
55
+ bundle install
56
+
57
+ ### Using the continuous integration server
58
+
59
+ You can test ActiveFedora using the same process as our continuous
60
+ integration server. To do that, unzip a copy\
61
+ of hydra-jetty first. This includes copies of Fedora and Solr which are
62
+ used during the testing process.
63
+
64
+ rake jetty:unzip
65
+
66
+ Once hydra-jetty is unzipped, the ci rake task will spin up jetty,
67
+ import the fixtures, and run the tests for you.
68
+
69
+ rake active_fedora:ci
70
+
71
+ ### Testing Manually
72
+
73
+ If you want to run the tests manually, follow these instructions.
74
+
75
+ You need to have a copy of hydra-jetty running. To do this, download a
76
+ working copy of
77
+ [hydra-jetty](https://github.com/projecthydra/hydra-jetty), cd into its
78
+ root and run
79
+
80
+ java -jar start.jar
81
+
82
+ Now you’re ready to run the tests. In the directory where active\_fedora
83
+ is installed, run
84
+
85
+ rake spec
86
+
87
+ Predicate Mappings
88
+ ------------------
89
+
90
+ ActiveFedora versions 2.2.1 and higher provides specialized control over
91
+ the predicate mappings used by SemanticNode. In order to provide your
92
+ own mappings, \
93
+ you must supply a predicate\_mappings.yml in the same format as the
94
+ config/predicate\_mappings.yml file shipped with the ActiveFedora gem.
95
+ Place the file in the same directory\
96
+ as your fedora.yml file and use the current method of initializing
97
+ ActiveFedora:
98
+
99
+ ActiveFedora.init("/path/to/my/config/fedora.yml")
100
+
101
+ If no predicate\_mappings.yml file is found, ActiveFedora will use the
102
+ default mappings.
103
+
104
+ Acknowledgements
105
+ ----------------
106
+
107
+ Creator: Matt Zumwalt ([MediaShelf](http://yourmediashelf.com))
108
+
109
+ Developers: \
110
+ Justin Coyne, McClain Looney & Eddie Shin
111
+ ([MediaShelf](http://yourmediashelf.com)), Rick Johnson (Notre Dame)
112
+
113
+ LICENSE:
114
+ --------
115
+
116
+ Copyright © 2009-2012 Matt Zumwalt & MediaShelf, LLC
117
+
118
+ This program is free software: you can redistribute it and/or modify\
119
+ it under the terms of the GNU Lesser General Public License (LGPL) as \
120
+ published by the Free Software Foundation, either version 3 of the
121
+ License, \
122
+ or (at your option) any later version.
123
+
124
+ This program is distributed in the hope that it will be useful,\
125
+ but WITHOUT ANY WARRANTY; without even the implied warranty of\
126
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\
127
+ GNU General Public License for more details.
128
+
129
+ You should have received a copy of the GNU Lesser General Public
130
+ License\
131
+ along with this program. If not, see <http://www.gnu.org/licenses/> or \
132
+ see <http://www.gnu.org/licenses/lgpl.html>.
133
+
134
+ The above copyright notice and this permission notice shall be\
135
+ included in all copies or substantial portions of the Software.
136
+
137
+ THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND,\
138
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\
139
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\
140
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY\
141
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\
142
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\
143
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile CHANGED
@@ -1,21 +1,19 @@
1
1
  require 'rake/clean'
2
2
  require 'rubygems'
3
3
  require 'bundler'
4
- require 'bundler/setup'
5
- require 'active-fedora'
4
+ require "bundler/setup"
5
+ require "active-fedora"
6
6
 
7
7
  Bundler::GemHelper.install_tasks
8
8
 
9
- # peg to an expected-to-match version of jetty, if not specified
10
- ZIP_URL ||= ENV['ZIP_URL'] || 'https://github.com/projecthydra/hydra-jetty/archive/v7.2.0.zip'
11
-
12
9
  # load rake tasks defined in lib/tasks that are not loaded in lib/active_fedora.rb
13
- load 'lib/tasks/active_fedora_dev.rake' if defined?(Rake)
10
+ load "lib/tasks/active_fedora_dev.rake"
14
11
 
15
12
  CLEAN.include %w[**/.DS_Store tmp *.log *.orig *.tmp **/*~]
16
13
 
17
- task :ci => ['jetty:clean', 'active_fedora:ci']
14
+ task :ci => ['jetty:clean', 'active_fedora:ci']
18
15
  task :spec => ['active_fedora:rspec']
19
16
  task :rcov => ['active_fedora:rcov']
20
17
 
18
+
21
19
  task :default => [:ci]
@@ -15,31 +15,31 @@ Gem::Specification.new do |s|
15
15
  s.required_ruby_version = '>= 1.9.3'
16
16
 
17
17
  s.add_dependency('rsolr')
18
- s.add_dependency('om', '~> 3.0')
18
+ s.add_dependency('om', '~> 3.0.0')
19
19
  s.add_dependency('nom-xml', '>=0.5.1')
20
- s.add_dependency("activesupport", '>= 3')
20
+ s.add_dependency("activesupport", '>= 3.0.0')
21
21
  s.add_dependency("mediashelf-loggable")
22
- s.add_dependency("rubydora", '~>1.6', '>= 1.6.5')
23
- s.add_dependency("rdf", '~> 1.1', '>= 1.1.1.1')
24
- s.add_dependency("rdf-rdfxml", '~>1.1')
22
+ s.add_dependency("rubydora", '~>1.7.0.pre1')
23
+ s.add_dependency("rdf")
24
+ s.add_dependency("rdf-rdfxml", '~>1.1.0')
25
25
  s.add_dependency("deprecation")
26
26
  s.add_development_dependency("rdoc")
27
27
  s.add_development_dependency("yard")
28
- s.add_development_dependency("RedCloth") # for RDoc formatting
29
28
  s.add_development_dependency("rake")
30
29
  s.add_development_dependency("jettywrapper", ">=1.4.0")
31
- s.add_development_dependency("rspec", "~> 2.99")
30
+ s.add_development_dependency("rspec", ">= 2.9.0")
32
31
  s.add_development_dependency("equivalent-xml")
33
32
  s.add_development_dependency("rest-client")
34
33
  s.add_development_dependency("webmock")
35
-
34
+
36
35
  s.files = `git ls-files`.split("\n")
37
36
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
38
37
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
39
38
  s.extra_rdoc_files = [
40
39
  "LICENSE",
41
- "README.textile"
40
+ "README.md"
42
41
  ]
43
42
  s.require_paths = ["lib"]
44
43
 
45
44
  end
45
+
@@ -0,0 +1,11 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec :path=>"../"
4
+
5
+ gem 'activemodel', '~> 3.2.13'
6
+
7
+ group :development, :test do
8
+ gem 'rcov', :platform => :mri_18
9
+ gem 'simplecov', :platform => :mri_19
10
+ gem 'simplecov-rcov', :platform => :mri_19
11
+ end
@@ -0,0 +1,10 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec :path=>"../"
4
+
5
+ gem 'activemodel', '~> 4.0.0'
6
+
7
+ group :development, :test do
8
+ gem 'simplecov', :platform => :mri_19
9
+ gem 'simplecov-rcov', :platform => :mri_19
10
+ end
@@ -22,28 +22,33 @@ module ActiveFedora #:nodoc:
22
22
  class AssociationTypeMismatch < RuntimeError; end # :nodoc:
23
23
  class UnregisteredPredicateError < RuntimeError; end # :nodoc:
24
24
  class RecordNotSaved < RuntimeError; end # :nodoc:
25
+ class IllegalOperation < RuntimeError; end # :nodoc:
25
26
 
26
27
 
27
28
  eager_autoload do
29
+ autoload :AssociationRelation
28
30
  autoload :Associations
29
31
  autoload :Attributes
30
32
  autoload :Auditable
33
+ autoload :AutosaveAssociation
31
34
  autoload :Base
32
35
  autoload :ContentModel
33
36
  autoload :Callbacks
34
37
  autoload :Config
38
+ autoload :Core
35
39
  autoload :Datastream
40
+ autoload :DatastreamAttribute
36
41
  autoload :DatastreamHash
37
42
  autoload :Datastreams
38
- autoload :Delegating
39
43
  autoload :DigitalObject
44
+ autoload :FedoraAttributes
40
45
  autoload :FileConfigurator
41
46
  autoload :Indexing
42
47
  autoload :Model
43
48
  autoload :NestedAttributes
44
- autoload :NokogiriDatastream
45
49
  autoload :NomDatastream
46
50
  autoload :NtriplesRDFDatastream
51
+ autoload :NullRelation
47
52
  autoload :OmDatastream
48
53
  autoload :Property
49
54
  autoload :Persistence
@@ -57,10 +62,22 @@ module ActiveFedora #:nodoc:
57
62
  autoload :RdfxmlRDFDatastream
58
63
  autoload :Reflection
59
64
  autoload :Relation
65
+
66
+ autoload_under 'relation' do
67
+ autoload :Calculations
68
+ autoload :Delegation
69
+ autoload :SpawnMethods
70
+ autoload :QueryMethods
71
+ autoload :FinderMethods
72
+ end
73
+
60
74
  autoload :RelationshipGraph
61
75
  autoload :RelsExtDatastream
62
- autoload :ServiceDefinitions
76
+ autoload :Scoping
63
77
  autoload :SemanticNode
78
+ autoload :ServiceDefinitions
79
+ autoload :Serialization
80
+ autoload :Sharding
64
81
  autoload :SimpleDatastream
65
82
  autoload :SolrDigitalObject
66
83
  autoload :SolrService
@@ -72,7 +89,17 @@ module ActiveFedora #:nodoc:
72
89
  autoload :Validations
73
90
  autoload :SolrInstanceLoader
74
91
  end
75
-
92
+
93
+ module Scoping
94
+ extend ActiveSupport::Autoload
95
+
96
+ eager_autoload do
97
+ autoload :Default
98
+ autoload :Named
99
+ end
100
+ end
101
+
102
+
76
103
 
77
104
  include Loggable
78
105
 
@@ -0,0 +1,18 @@
1
+ module ActiveFedora
2
+ class AssociationRelation < Relation
3
+ def initialize(klass, association)
4
+ super(klass)
5
+ @association = association
6
+ end
7
+
8
+ def proxy_association
9
+ @association
10
+ end
11
+
12
+ private
13
+
14
+ def exec_queries
15
+ super.each { |r| @association.set_inverse_instance r }
16
+ end
17
+ end
18
+ end
@@ -5,13 +5,26 @@ module ActiveFedora
5
5
  module Associations
6
6
  extend ActiveSupport::Concern
7
7
 
8
- autoload :HasManyAssociation, 'active_fedora/associations/has_many_association'
9
- autoload :BelongsToAssociation, 'active_fedora/associations/belongs_to_association'
8
+ autoload :Association, 'active_fedora/associations/association'
9
+ autoload :AssociationScope, 'active_fedora/associations/association_scope'
10
+ autoload :SingularAssociation, 'active_fedora/associations/singular_association'
11
+ autoload :CollectionAssociation, 'active_fedora/associations/collection_association'
12
+ autoload :CollectionProxy, 'active_fedora/associations/collection_proxy'
13
+
14
+ autoload :HasManyAssociation, 'active_fedora/associations/has_many_association'
15
+ autoload :BelongsToAssociation, 'active_fedora/associations/belongs_to_association'
10
16
  autoload :HasAndBelongsToManyAssociation, 'active_fedora/associations/has_and_belongs_to_many_association'
11
17
 
18
+ module Builder
19
+ autoload :Association, 'active_fedora/associations/builder/association'
20
+ autoload :SingularAssociation, 'active_fedora/associations/builder/singular_association'
21
+ autoload :CollectionAssociation, 'active_fedora/associations/builder/collection_association'
22
+
23
+ autoload :BelongsTo, 'active_fedora/associations/builder/belongs_to'
24
+ autoload :HasMany, 'active_fedora/associations/builder/has_many'
25
+ autoload :HasAndBelongsToMany, 'active_fedora/associations/builder/has_and_belongs_to_many'
26
+ end
12
27
 
13
- autoload :AssociationCollection, 'active_fedora/associations/association_collection'
14
- autoload :AssociationProxy, 'active_fedora/associations/association_proxy'
15
28
 
16
29
  # Clears out the association cache.
17
30
  def clear_association_cache #:nodoc:
@@ -20,6 +33,21 @@ module ActiveFedora
20
33
 
21
34
  # :nodoc:
22
35
  attr_reader :association_cache
36
+
37
+
38
+ # Returns the association instance for the given name, instantiating it if it doesn't already exist
39
+ def association(name) #:nodoc:
40
+ association = association_instance_get(name)
41
+
42
+ if association.nil?
43
+ reflection = self.class.reflect_on_association(name)
44
+ association = reflection.association_class.new(self, reflection)
45
+ association_instance_set(name, association)
46
+ end
47
+
48
+ association
49
+ end
50
+
23
51
 
24
52
  private
25
53
 
@@ -35,10 +63,8 @@ module ActiveFedora
35
63
 
36
64
  module ClassMethods
37
65
 
38
- def has_many(association_id, options={})
39
- reflection = create_has_many_reflection(association_id, options)
40
- add_association_callbacks(reflection.name, reflection.options)
41
- collection_accessor_methods(reflection, HasManyAssociation)
66
+ def has_many(name, options={})
67
+ Builder::HasMany.build(self, name, options)
42
68
  end
43
69
 
44
70
 
@@ -75,14 +101,9 @@ module ActiveFedora
75
101
  # Option examples:
76
102
  # belongs_to :firm, :property => :client_of
77
103
  # belongs_to :author, :class_name => "Person", :property => :author_of
78
- def belongs_to(association_id, options = {})
104
+ def belongs_to(name, options = {})
79
105
  raise "You must specify a property name for #{name}" if !options[:property]
80
- reflection = create_belongs_to_reflection(association_id, options)
81
-
82
- association_accessor_methods(reflection, BelongsToAssociation)
83
- association_constructor_method(:build, reflection, BelongsToAssociation)
84
- association_constructor_method(:create, reflection, BelongsToAssociation)
85
- #configure_dependency_for_belongs_to(reflection)
106
+ Builder::BelongsTo.build(self, name, options)
86
107
  end
87
108
 
88
109
 
@@ -148,163 +169,9 @@ module ActiveFedora
148
169
  # has_and_belongs_to_many :projects, :property=>:works_on
149
170
  # has_and_belongs_to_many :nations, :class_name => "Country", :property=>:is_citizen_of
150
171
  # has_and_belongs_to_many :topics, :property=>:has_topic, :inverse_of=>:is_topic_of
151
- def has_and_belongs_to_many(association_id, options = {}, &extension)
152
- reflection = create_has_and_belongs_to_many_reflection(association_id, options, &extension)
153
- collection_accessor_methods(reflection, HasAndBelongsToManyAssociation)
154
- #configure_after_destroy_method_for_has_and_belongs_to_many(reflection)
155
- add_association_callbacks(reflection.name, options)
172
+ def has_and_belongs_to_many(name, options = {})
173
+ Builder::HasAndBelongsToMany.build(self, name, options)
156
174
  end
157
-
158
-
159
- private
160
-
161
- def create_has_many_reflection(association_id, options)
162
- create_reflection(:has_many, association_id, options, self)
163
- #collection_accessor_methods(reflection, HasManyAssociation)
164
- end
165
-
166
- def create_belongs_to_reflection(association_id, options)
167
- create_reflection(:belongs_to, association_id, options, self)
168
- end
169
-
170
- def create_has_and_belongs_to_many_reflection(association_id, options)
171
- create_reflection(:has_and_belongs_to_many, association_id, options, self)
172
- end
173
-
174
- def add_association_callbacks(association_name, options)
175
- callbacks = %w(before_add after_add before_remove after_remove)
176
- callbacks.each do |callback_name|
177
- full_callback_name = "#{callback_name}_for_#{association_name}"
178
- defined_callbacks = options[callback_name.to_sym]
179
- class_attribute full_callback_name.to_sym
180
- if options.has_key?(callback_name.to_sym)
181
- self.send((full_callback_name +'=').to_sym, [defined_callbacks].flatten)
182
- else
183
- self.send((full_callback_name +'=').to_sym, [])
184
- end
185
- end
186
- end
187
-
188
- def association_accessor_methods(reflection, association_proxy_class)
189
- redefine_method(reflection.name) do |*params|
190
- force_reload = params.first unless params.empty?
191
- association = association_instance_get(reflection.name)
192
-
193
- if association.nil? || force_reload
194
- association = association_proxy_class.new(self, reflection)
195
- retval = force_reload ? reflection.klass.uncached { association.reload } : association.reload
196
- if retval.nil? and association_proxy_class == BelongsToAssociation
197
- association_instance_set(reflection.name, nil)
198
- return nil
199
- end
200
- association_instance_set(reflection.name, association)
201
- end
202
-
203
- association.target.nil? ? nil : association
204
- end
205
-
206
- redefine_method("loaded_#{reflection.name}?") do
207
- association = association_instance_get(reflection.name)
208
- association && association.loaded?
209
- end
210
-
211
- redefine_method("#{reflection.name}=") do |new_value|
212
- association = association_instance_get(reflection.name)
213
-
214
- if association.nil? || association.target != new_value
215
- association = association_proxy_class.new(self, reflection)
216
- end
217
-
218
- association.replace(new_value)
219
- association_instance_set(reflection.name, new_value.nil? ? nil : association)
220
- end
221
-
222
- redefine_method("set_#{reflection.name}_target") do |target|
223
- return if target.nil? and association_proxy_class == BelongsToAssociation
224
- association = association_proxy_class.new(self, reflection)
225
- association.target = target
226
- association_instance_set(reflection.name, association)
227
- end
228
-
229
- redefine_method("#{reflection.name}_id=") do |new_value|
230
- options = reflection.klass == ActiveFedora::Base ? {cast: true} : {}
231
- obj = new_value.blank? ? nil : reflection.klass.find(new_value, options)
232
- send("#{reflection.name}=", obj)
233
- end
234
- redefine_method("#{reflection.name}_id") do
235
- obj = send("#{reflection.name}")
236
- obj.pid if obj
237
- end
238
- end
239
-
240
-
241
- def collection_reader_method(reflection, association_proxy_class)
242
- redefine_method(reflection.name) do |*params|
243
-
244
- if (params.first.is_a?(Hash) && params.first[:response_format] == :solr)
245
- load_from_solr = true
246
- force_reload = false
247
- else
248
- force_reload = params.first unless params.empty?
249
- end
250
- association = association_instance_get(reflection.name)
251
- unless association
252
- association = association_proxy_class.new(self, reflection)
253
- association_instance_set(reflection.name, association)
254
- end
255
-
256
- association.reload if force_reload
257
- return association.load_from_solr if load_from_solr
258
-
259
- association
260
- end
261
-
262
- redefine_method("#{reflection.name.to_s.singularize}_ids") do
263
- send(reflection.name).map { |r| r.pid }
264
- end
265
-
266
- end
267
-
268
-
269
- def collection_accessor_methods(reflection, association_proxy_class, writer = true)
270
- collection_reader_method(reflection, association_proxy_class)
271
-
272
- if writer
273
- redefine_method("#{reflection.name}=") do |new_value|
274
- # Loads proxy class instance (defined in collection_reader_method) if not already loaded
275
- association = send(reflection.name)
276
- association.replace(new_value)
277
- association
278
- end
279
-
280
- redefine_method("#{reflection.name.to_s.singularize}_ids=") do |new_value|
281
- ids = (new_value || []).reject { |nid| nid.blank? }
282
- #TODO, like this when find() can return multiple records
283
- #send("#{reflection.name}=", reflection.klass.find(ids))
284
- opts = reflection.klass == ActiveFedora::Base ? {cast: true} : nil
285
- send("#{reflection.name}=", ids.collect { |id| reflection.klass.find(id, opts)})
286
- end
287
- end
288
- end
289
-
290
- def association_constructor_method(constructor, reflection, association_proxy_class)
291
- redefine_method("#{constructor}_#{reflection.name}") do |*params|
292
- attributees = params.first unless params.empty?
293
- replace_existing = params[1].nil? ? true : params[1]
294
- association = association_instance_get(reflection.name)
295
-
296
- unless association
297
- association = association_proxy_class.new(self, reflection)
298
- association_instance_set(reflection.name, association)
299
- end
300
-
301
- # if association_proxy_class == HasOneAssociation
302
- # association.send(constructor, attributees, replace_existing)
303
- # else
304
- association.send(constructor, attributees)
305
- #end
306
- end
307
- end
308
175
  end
309
176
  end
310
177
  end