active-fedora 9.0.0 → 9.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (89) hide show
  1. checksums.yaml +4 -4
  2. data/History.txt +97 -0
  3. data/README.md +40 -28
  4. data/active-fedora.gemspec +2 -1
  5. data/lib/active_fedora/associations/builder/contains.rb +5 -1
  6. data/lib/active_fedora/associations/builder/has_many.rb +1 -1
  7. data/lib/active_fedora/associations/collection_association.rb +1 -18
  8. data/lib/active_fedora/associations/contains_association.rb +3 -1
  9. data/lib/active_fedora/associations/has_and_belongs_to_many_association.rb +12 -10
  10. data/lib/active_fedora/associations.rb +1 -1
  11. data/lib/active_fedora/attached_files.rb +7 -4
  12. data/lib/active_fedora/attributes/property_builder.rb +1 -0
  13. data/lib/active_fedora/attributes.rb +36 -9
  14. data/lib/active_fedora/change_set.rb +2 -2
  15. data/lib/active_fedora/clean_connection.rb +40 -0
  16. data/lib/active_fedora/core/fedora_id_translator.rb +12 -0
  17. data/lib/active_fedora/core/fedora_uri_translator.rb +9 -0
  18. data/lib/active_fedora/core.rb +26 -38
  19. data/lib/active_fedora/errors.rb +4 -0
  20. data/lib/active_fedora/fedora.rb +22 -4
  21. data/lib/active_fedora/fedora_attributes.rb +25 -1
  22. data/lib/active_fedora/file.rb +30 -24
  23. data/lib/active_fedora/indexing/map.rb +46 -0
  24. data/lib/active_fedora/indexing.rb +14 -0
  25. data/lib/active_fedora/inheritable_accessors.rb +26 -0
  26. data/lib/active_fedora/loadable_from_json.rb +5 -1
  27. data/lib/active_fedora/nom_datastream.rb +6 -4
  28. data/lib/active_fedora/persistence.rb +11 -7
  29. data/lib/active_fedora/rdf/datastream_indexing.rb +4 -0
  30. data/lib/active_fedora/rdf/fcrepo4.rb +1 -0
  31. data/lib/active_fedora/rdf/indexing_service.rb +18 -11
  32. data/lib/active_fedora/rdf/ldp.rb +3 -0
  33. data/lib/active_fedora/rdf/ntriples_rdf_datastream.rb +0 -4
  34. data/lib/active_fedora/rdf/rdf_datastream.rb +12 -1
  35. data/lib/active_fedora/reflection.rb +3 -1
  36. data/lib/active_fedora/relation/finder_methods.rb +36 -5
  37. data/lib/active_fedora/solr_query_builder.rb +1 -1
  38. data/lib/active_fedora/solr_service.rb +1 -1
  39. data/lib/active_fedora/version.rb +1 -1
  40. data/lib/active_fedora/versions_graph.rb +7 -8
  41. data/lib/active_fedora.rb +6 -0
  42. data/spec/integration/associations_spec.rb +64 -21
  43. data/spec/integration/attached_files_spec.rb +24 -0
  44. data/spec/integration/attributes_spec.rb +49 -3
  45. data/spec/integration/belongs_to_association_spec.rb +118 -47
  46. data/spec/integration/clean_connection_spec.rb +21 -0
  47. data/spec/integration/collection_association_spec.rb +46 -0
  48. data/spec/integration/field_to_solr_name_spec.rb +11 -7
  49. data/spec/integration/has_and_belongs_to_many_associations_spec.rb +180 -137
  50. data/spec/integration/has_many_associations_spec.rb +6 -2
  51. data/spec/integration/json_serialization_spec.rb +11 -5
  52. data/spec/integration/nested_attribute_spec.rb +3 -1
  53. data/spec/integration/ntriples_datastream_spec.rb +23 -17
  54. data/spec/integration/persistence_spec.rb +3 -1
  55. data/spec/integration/query_result_builder_spec.rb +2 -2
  56. data/spec/integration/relation_delegation_spec.rb +3 -1
  57. data/spec/integration/scoped_query_spec.rb +3 -1
  58. data/spec/integration/solr_instance_loader_spec.rb +4 -2
  59. data/spec/integration/versionable_spec.rb +38 -1
  60. data/spec/samples/samples.rb +0 -1
  61. data/spec/spec_helper.rb +1 -0
  62. data/spec/unit/active_fedora_spec.rb +4 -2
  63. data/spec/unit/attributes_spec.rb +52 -12
  64. data/spec/unit/base_active_model_spec.rb +5 -3
  65. data/spec/unit/base_spec.rb +102 -2
  66. data/spec/unit/callback_spec.rb +4 -2
  67. data/spec/unit/change_set_spec.rb +4 -2
  68. data/spec/unit/core/fedora_id_translator_spec.rb +20 -0
  69. data/spec/unit/core/fedora_uri_translator_spec.rb +19 -0
  70. data/spec/unit/core_spec.rb +54 -2
  71. data/spec/unit/has_many_association_spec.rb +27 -2
  72. data/spec/unit/ntriples_datastream_spec.rb +24 -20
  73. data/spec/unit/qualified_dublin_core_datastream_spec.rb +0 -6
  74. data/spec/unit/query_result_builder_spec.rb +1 -1
  75. data/spec/unit/rdf/indexing_service_spec.rb +19 -17
  76. data/spec/unit/rdf_resource_datastream_spec.rb +14 -10
  77. data/spec/unit/reflection_spec.rb +44 -0
  78. data/spec/unit/simple_datastream_spec.rb +34 -0
  79. data/spec/unit/solr_query_builder_spec.rb +1 -1
  80. data/spec/unit/validations_spec.rb +4 -2
  81. metadata +28 -13
  82. data/spec/samples/marpa-dc_datastream.rb +0 -102
  83. data/spec/samples/models/audio_record.rb +0 -29
  84. data/spec/samples/models/image.rb +0 -5
  85. data/spec/samples/models/oral_history.rb +0 -36
  86. data/spec/samples/models/seminar.rb +0 -29
  87. data/spec/samples/models/seminar_audio_file.rb +0 -32
  88. data/spec/samples/oral_history_sample_model.rb +0 -30
  89. data/spec/samples/special_thing.rb +0 -44
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 871591e4b1778c1b10fe6b66bd59d42cc6705607
4
- data.tar.gz: 7e11bc3fdf8410f813e0bc9dd36fb5e015f2607d
3
+ metadata.gz: db07402e3e8ca081253507888ffda0d81084c947
4
+ data.tar.gz: 3b1ae9595815772239fb91fa04713afdb736a61e
5
5
  SHA512:
6
- metadata.gz: d67858d7e6c9bbcbcc7761e929d454aa817e5063a7094eb0645c042e057b27e4e97e8aa2b8447119fd3796781be448a39087fa61acadfae9db448b0a28c3b761
7
- data.tar.gz: c1a1612ff58d19b86806da7dcb0b421ba6769413ceec565b1dcf030e18d57c5e9f6e1229976d119b2c048e6c1b096893b964741fb6ef7a298131e11bf6854dde
6
+ metadata.gz: b8db754769fb5d0a4a93ee0b58304f92080a5d6ecec2a9e3730fdbbe623aa505af85b8c8a88d22ab9be86c93d118395c6134fe85b219b65b0bac091410a57675
7
+ data.tar.gz: 01b0a5c53e12d3426ae309fdc80af82197ede177ee617ec7da0be468e99841da6e8f0a1db14b0d231b524c3658db3a704bc6ad8dc30f8b9c01726d44ef3bc99a
data/History.txt CHANGED
@@ -1,3 +1,100 @@
1
+ v9.1.0
2
+ 2015-04-16: Use delegate_to instead of datastream in the options for property
3
+ Trying to reduce/elimnate the useage of "datastream" especially in the public
4
+ API. [Justin Coyne]
5
+
6
+ 2015-04-15: Bump version to 9.1.0.rc1 [Justin Coyne]
7
+
8
+ 2015-04-15: Bump version to 9.1.0.alpha [ci skip] [Justin Coyne]
9
+
10
+ 2015-04-08: Fix deleting from a HABTM when the inverse_of is a has_many. Fixes
11
+ #763 [Justin Coyne]
12
+
13
+ 2015-04-07: Remove a spec that is a duplicate of
14
+ integration/collection_association_spec.rb:92 [Justin Coyne]
15
+
16
+ 2015-04-07: Leverage the code in AssociationRelation to find the inverse. Fixes
17
+ #760 [Justin Coyne]
18
+
19
+ 2015-04-10: Make #translate_id_to_uri/uri_to_id reliable. [Trey Terrell]
20
+
21
+ 2015-04-02: Find best model match in case of inheritance [Stuart Kenny]
22
+
23
+ 2015-04-10: Requires 'deprecation' for ActiveFedora::File [Andrew Myers]
24
+
25
+ 2015-04-06: Only set/save the inverse on a HABTM if the inverse is also HABTM
26
+ previously we were getting: [Justin Coyne]
27
+
28
+ 2015-04-06: Derive a foreign_key ending with `_ids` if the inverse is a
29
+ collection [Justin Coyne]
30
+
31
+ 2015-04-06: Find inverse relations when class_names have modules [Justin Coyne]
32
+
33
+ 2015-04-06: Raise an error when the inverse relationship can not be found.
34
+ Previously a "SystemStackError: Stack too deep" was encountered in this
35
+ situation [Justin Coyne]
36
+
37
+ 2015-04-02: Add a mechanism to set rdf_label on the ActiveTriple resource
38
+ [Justin Coyne]
39
+
40
+ 2015-04-03: Add CleanConnection [Trey Terrell]
41
+
42
+ 2015-04-02: The indexing hints should be inheritable [Justin Coyne]
43
+
44
+ 2015-04-03: Refactor has_and_belongs_to_many_associations_spec [Justin Coyne]
45
+
46
+ 2015-04-03: Remove unused sample classes [Justin Coyne]
47
+
48
+ 2015-04-02: Sort versions as dates not as strings [Michael J. Giarlo]
49
+
50
+ 2015-03-27: Allow property to delegate to a datastream. Ref #736 [Justin Coyne]
51
+
52
+ 2015-04-01: Prevents an object from being loaded to the incorrect class. For
53
+ example, when loading a batch object it should be loaded into a Batch (and not a
54
+ File for example.) [Hector Correa]
55
+
56
+ 2015-03-30: Groundskeeping: YARD cleanup [Joe Atzberger]
57
+
58
+ 2015-03-27: Move the indexing logic to the model. Fixes #736 You should now add
59
+ indexing hints to has_attributes by passing a block similar to how you do it
60
+ with rdf properties. e.g.: [Justin Coyne]
61
+
62
+ 2015-03-27: YARD syntax is @return, not @returns [Joe Atzberger]
63
+
64
+ 2015-03-27: Last touch up on README [Joe Atzberger]
65
+
66
+ 2015-03-27: README touchup [Joe Atzberger]
67
+
68
+ 2015-03-27: Formatting for README [Joe Atzberger]
69
+
70
+ v9.0.6
71
+ 2015-03-26: Setting type should not wipe out properties. Fixes #737 [Justin Coyne]
72
+
73
+ v9.0.5
74
+ 2015-03-25: Properties named *_id should not break the change set [Chris Colvard]
75
+
76
+ 2015-03-24: Add rdf:type assertions to ActiveFedora::Base [Justin Coyne]
77
+
78
+ 2015-03-24: Add documentation that differentiates attach_file from add_file [Justin Coyne]
79
+
80
+ 2015-03-24: Remove #default_attributes. Fixes #732 [Chris Colvard]
81
+
82
+ 2015-03-18: Make sure datastreams get configured on load as well as new/create [Michael B. Klein]
83
+
84
+ 2015-03-17: Allow a has_many association to specify an explicit foreign key via the :as option [Michael B. Klein]
85
+
86
+ v9.0.4
87
+ 2015-03-10: Refactor the AF::Base initializer [Justin Coyne]
88
+
89
+ 2015-03-10: Added missing id setter [Justin Coyne]
90
+
91
+ v9.0.3
92
+ 2015-03-04: Encapsulate solr_escape and make it private [Justin Coyne]
93
+
94
+ 2015-03-04: Update readme [Justin Coyne]
95
+
96
+ 2015-02-28: Use modified RSolr.solr_escape method [Adam Wead]
97
+
1
98
  v9.0.0
2
99
  2015-01-30: When save! is called only validate once [Justin Coyne]
3
100
 
data/README.md CHANGED
@@ -6,12 +6,10 @@ Description
6
6
  [![Dependencies](https://gemnasium.com/projecthydra/active_fedora.png)](https://gemnasium.com/projecthydra/active\_fedora)
7
7
  [![Coverage Status](https://img.shields.io/coveralls/projecthydra/active_fedora.svg)](https://coveralls.io/r/projecthydra/active_fedora)
8
8
 
9
- Rubydora and ActiveFedora provide a set of Ruby gems for creating and
9
+ ActiveFedora is a Ruby gem for creating and
10
10
  managing objects in the Fedora Repository Architecture
11
11
  ([http://fedora-commons.org](http://fedora-commons.org)). ActiveFedora
12
- is loosely based on “ActiveRecord” in Rails. The 3.x series of
13
- ActiveFedora depends on Rails 3, specifically activemodel and
14
- activesupport.
12
+ is loosely based on “ActiveRecord” in Rails. Version 9.0+ works with Fedora 4 and prior versions work on Fedora 3.
15
13
 
16
14
  Getting Help
17
15
  ------------
@@ -25,21 +23,24 @@ Installation
25
23
 
26
24
  The gem is hosted on rubygems.
27
25
 
28
- gem install active-fedora
26
+ ```bash
27
+ gem install active-fedora
28
+ ```
29
29
 
30
30
  Getting Started
31
31
  ---------------
32
32
 
33
33
  The [Dive into Hydra](https://github.com/projecthydra/hydra/wiki/Dive-into-Hydra)
34
- gives you a brief tour through ActiveFedora’s features on the command
35
- line.
34
+ gives you a brief tour through ActiveFedora’s features on the command line.
36
35
 
37
36
  Generators
38
37
  ----------
39
38
 
40
39
  You can generate a model inheriting from ActiveFedora::Base.
41
40
 
42
- rails generate active_fedora:model Book
41
+ ```bash
42
+ rails generate active_fedora:model Book
43
+ ```
43
44
 
44
45
  Testing (this Gem)
45
46
  ------------------
@@ -48,25 +49,30 @@ In order to run the RSpec tests, you need to have a copy of the
48
49
  ActiveFedora source code, and then run bundle install in the source
49
50
  directory. Testing requires hydra-jetty, which contains version for
50
51
  Fedora and Solr. Setting up and maintaining hydra-jetty for the purposes
51
- of testing this gem is all accomplished via
52
+ of testing this gem is all accomplished via:
52
53
 
53
- git clone https://github.com/projecthydra/active_fedora.git
54
- cd /wherever/active_fedora/is
55
- bundle install
54
+ ```bash
55
+ git clone https://github.com/projecthydra/active_fedora.git
56
+ cd active_fedora # or whatever directory your clone is in
57
+ bundle install
58
+ ```
56
59
 
57
60
  ### Using the continuous integration server
58
61
 
59
62
  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
63
+ integration server. To do that, unzip a copy of hydra-jetty first. This includes copies of Fedora and Solr which are
62
64
  used during the testing process.
63
65
 
64
- rake jetty:unzip
66
+ ```bash
67
+ rake jetty:unzip
68
+ ```
65
69
 
66
70
  Once hydra-jetty is unzipped, the ci rake task will spin up jetty,
67
71
  import the fixtures, and run the tests for you.
68
72
 
69
- rake active_fedora:ci
73
+ ```bash
74
+ rake active_fedora:ci
75
+ ```
70
76
 
71
77
  ### Testing Manually
72
78
 
@@ -75,30 +81,36 @@ If you want to run the tests manually, follow these instructions.
75
81
  You need to have a copy of hydra-jetty running. To do this, download a
76
82
  working copy of
77
83
  [hydra-jetty](https://github.com/projecthydra/hydra-jetty), cd into its
78
- root and run
84
+ root and run:
79
85
 
80
- java -jar start.jar
86
+ ```bash
87
+ java -jar start.jar
88
+ ```
81
89
 
82
- Now you’re ready to run the tests. In the directory where active\_fedora
83
- is installed, run
90
+ Now you’re ready to run the tests. In the directory where active_fedora
91
+ is installed, run:
84
92
 
85
- rake spec
93
+ ```bash
94
+ rake spec
95
+ ```
86
96
 
87
97
  Predicate Mappings
88
98
  ------------------
89
99
 
90
100
  ActiveFedora versions 2.2.1 and higher provides specialized control over
91
101
  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
102
+ own mappings,
103
+ you must supply a `predicate_mappings.yml` in the same format as the
104
+ `config/predicate_mappings.yml` file shipped with the ActiveFedora gem.
105
+ Place the file in the same directory
106
+ as your `fedora.yml` file and use the current method of initializing
97
107
  ActiveFedora:
98
108
 
99
- ActiveFedora.init("/path/to/my/config/fedora.yml")
109
+ ```ruby
110
+ ActiveFedora.init("/path/to/my/config/fedora.yml")
111
+ ```
100
112
 
101
- If no predicate\_mappings.yml file is found, ActiveFedora will use the
113
+ If no `predicate_mappings.yml` file is found, ActiveFedora will use the
102
114
  default mappings.
103
115
 
104
116
  Acknowledgements
@@ -22,7 +22,7 @@ Gem::Specification.new do |s|
22
22
  s.add_dependency "rdf-rdfxml", '~> 1.1.0'
23
23
  s.add_dependency "linkeddata"
24
24
  s.add_dependency "deprecation"
25
- s.add_dependency "ldp", '~> 0.2.1'
25
+ s.add_dependency "ldp", '~> 0.3.0'
26
26
  s.add_dependency "rdf-ldp"
27
27
 
28
28
  s.add_development_dependency "rdoc"
@@ -30,6 +30,7 @@ Gem::Specification.new do |s|
30
30
  s.add_development_dependency "rake"
31
31
  s.add_development_dependency "jettywrapper", ">= 2.0.0"
32
32
  s.add_development_dependency "rspec", "~> 3.0"
33
+ s.add_development_dependency "rspec-its"
33
34
  s.add_development_dependency "equivalent-xml"
34
35
  s.add_development_dependency "simplecov", '~> 0.7.1'
35
36
 
@@ -19,7 +19,11 @@ module ActiveFedora::Associations::Builder
19
19
  mixin.send(:define_method, name) do |*params|
20
20
  association(name).reader(*params).tap do |file|
21
21
  set_uri = uri.kind_of?(RDF::URI) ? uri.value.present? : uri.present?
22
- file.uri = "#{uri}/#{name}" if set_uri
22
+ if set_uri
23
+ file_uri = "#{uri}/#{name}"
24
+ file.uri = file_uri
25
+ file.exists! if contains_assertions.include?(file_uri)
26
+ end
23
27
  end
24
28
  end
25
29
  end
@@ -2,7 +2,7 @@ module ActiveFedora::Associations::Builder
2
2
  class HasMany < CollectionAssociation #:nodoc:
3
3
  self.macro = :has_many
4
4
 
5
- self.valid_options += [:dependent, :inverse_of]
5
+ self.valid_options += [:as, :dependent, :inverse_of]
6
6
 
7
7
  def build
8
8
  reflection = super
@@ -343,29 +343,12 @@ module ActiveFedora
343
343
  def find_reflection
344
344
  return reflection if @reflection.options[:predicate]
345
345
  if @reflection.class_name && @reflection.class_name != 'ActiveFedora::Base' && @reflection.macro != :has_and_belongs_to_many
346
- inverse_relation = @owner.class.to_s.underscore.to_sym
347
- begin
348
- find_reflection_for_relation(@reflection.class_name.constantize)
349
- rescue NameError
350
- raise "No :predicate attribute was set or could be inferred for #{@reflection.macro} #{@reflection.name.inspect} on #{@owner.class}"
351
- end
346
+ @reflection.inverse_of || raise("No :inverse_of or :predicate attribute was set or could be inferred for #{@reflection.macro} #{@reflection.name.inspect} on #{@owner.class}")
352
347
  else
353
348
  raise "Couldn't find reflection"
354
349
  end
355
350
  end
356
351
 
357
- def find_reflection_for_relation(klass, inverse_relation=@owner.class.to_s.underscore.to_sym)
358
- raise "Unable to lookup the :predicate attribute for #{@reflection.macro} #{@reflection.name.inspect} on #{@owner.class} because #{klass} specifies \"class_name: 'ActiveFedora::Base'\". Either specify a specific class_name in #{klass} or set :predicate in the #{@reflection.macro} declaration on #{@owner.class}" if inverse_relation == :'active_fedora/base'
359
- if klass.reflections.key?(inverse_relation)
360
- # Try it singular
361
- return klass.reflections[inverse_relation]
362
- elsif klass.reflections.key?(inverse_relation.to_s.pluralize.to_sym)
363
- # Try it plural
364
- return klass.reflections[inverse_relation.to_s.pluralize.to_sym]
365
- end
366
- find_reflection_for_relation(klass, @owner.class.superclass.to_s.underscore.to_sym)
367
- end
368
-
369
352
  def create_record(attributes, raise = false)
370
353
  attributes.update(@reflection.options[:conditions]) if @reflection.options[:conditions].is_a?(Hash)
371
354
  ensure_owner_is_not_new
@@ -7,7 +7,9 @@ module ActiveFedora
7
7
  end
8
8
 
9
9
  def find_target
10
- reflection.build_association(target_uri)
10
+ reflection.build_association(target_uri).tap do |record|
11
+ configure_datastream(record) if reflection.options[:block]
12
+ end
11
13
  end
12
14
 
13
15
  def target_uri
@@ -18,13 +18,16 @@ module ActiveFedora
18
18
  owner[reflection.foreign_key] ||= []
19
19
  owner[reflection.foreign_key] += [record.id]
20
20
 
21
- if @owner.new_record? and @reflection.options[:inverse_of]
22
- ActiveFedora::Base.logger.warn("has_and_belongs_to_many #{@reflection.inspect} is cowardly refusing to insert the inverse relationship into #{record}, because #{@owner} is not persisted yet.") if ActiveFedora::Base.logger
23
- elsif @reflection.options[:inverse_of]
24
- inverse = @reflection.inverse_of
25
- record[inverse.foreign_key] ||= []
26
- record[inverse.foreign_key] += [owner.id]
27
- record.save
21
+ # Only if they've explicitly stated the inverse in the options
22
+ if reflection.options[:inverse_of]
23
+ inverse = reflection.inverse_of
24
+ if owner.new_record?
25
+ ActiveFedora::Base.logger.warn("has_and_belongs_to_many #{reflection.inspect} is cowardly refusing to insert the inverse relationship into #{record}, because #{owner} is not persisted yet.") if ActiveFedora::Base.logger
26
+ elsif inverse.has_and_belongs_to_many?
27
+ record[inverse.foreign_key] ||= []
28
+ record[inverse.foreign_key] += [owner.id]
29
+ record.save
30
+ end
28
31
  end
29
32
 
30
33
  return true
@@ -76,9 +79,8 @@ module ActiveFedora
76
79
  records.each do |r|
77
80
  owner[reflection.foreign_key] -= [r.id]
78
81
 
79
- if (@reflection.options[:inverse_of])
80
- inverse = @reflection.inverse_of
81
- r[inverse.foreign_key] -= [owner.id]
82
+ if inverse = @reflection.inverse_of
83
+ r[inverse.foreign_key] -= [owner.id] if inverse.has_and_belongs_to_many?
82
84
  r.association(inverse.name).reset
83
85
  r.save
84
86
  end
@@ -86,7 +86,7 @@ module ActiveFedora
86
86
  # Note that this method doesn't actually execute the block, but stores it, to be executed
87
87
  # by any the implementation of the datastream(specified as :class_name)
88
88
  #
89
- # @param [String] :name the handle to refer to this child as
89
+ # @param [String] name the handle to refer to this child as
90
90
  # @param [Hash] options
91
91
  # @option options [Class] :class_name The class that will represent this child, should extend ``ActiveFedora::File''
92
92
  # @option options [String] :url
@@ -53,7 +53,10 @@ module ActiveFedora
53
53
  end
54
54
  end
55
55
 
56
- # Adds datastream to the object.
56
+ # Add an ActiveFedora::File to the object.
57
+ # @param [ActiveFedora::File] file
58
+ # @param [String] file_path
59
+ # @param [Hash] opts
57
60
  # @return [String] path of the added datastream
58
61
  def attach_file(file, file_path, opts={})
59
62
  create_singleton_association(file_path)
@@ -80,10 +83,10 @@ module ActiveFedora
80
83
  add_file(file, opts)
81
84
  end
82
85
 
83
- # Attach the given file to object
86
+ # Attach the given stream/string to object
84
87
  #
85
- # @param [File] file the file to add
86
- # @param [Hash] opts options: :dsid, :prefix, :mime_type
88
+ # @param [IO, String] file the file to add
89
+ # @param [Hash] args options: :dsid, :prefix, :mime_type
87
90
  # @option opts [String] :path The file path
88
91
  # @option opts [String] :prefix The path prefix (for auto-generated path)
89
92
  # @option opts [String] :mime_type The Mime-Type of the file
@@ -54,6 +54,7 @@ module ActiveFedora::Attributes
54
54
  end
55
55
 
56
56
  def build(&block)
57
+ #TODO remove this block stuff
57
58
  NodeConfig.new(name, options[:predicate], options.except(:predicate)) do |config|
58
59
  config.with_index(&block) if block_given?
59
60
  end
@@ -1,7 +1,10 @@
1
1
  require 'active_model/forbidden_attributes_protection'
2
+ require 'deprecation'
2
3
  module ActiveFedora
3
4
  module Attributes
4
5
  extend ActiveSupport::Concern
6
+ extend Deprecation
7
+ self.deprecation_horizon = 'ActiveFedora 10.0'
5
8
  include ActiveModel::Dirty
6
9
  include ActiveModel::ForbiddenAttributesProtection
7
10
 
@@ -144,15 +147,13 @@ module ActiveFedora
144
147
  @delegated_attributes = val
145
148
  end
146
149
 
147
- def has_attributes(*fields)
150
+ def has_attributes(*fields, &block)
148
151
  options = fields.pop
149
- datastream = options.delete(:datastream).to_s
150
- raise ArgumentError, "You must provide a datastream to has_attributes" if datastream.blank?
151
- define_attribute_methods fields
152
- fields.each do |f|
153
- create_attribute_reader(f, datastream, options)
154
- create_attribute_setter(f, datastream, options)
155
- end
152
+ delegate_target = options.delete(:datastream)
153
+ raise ArgumentError, "You must provide a datastream to has_attributes" if delegate_target.blank?
154
+ Deprecation.warn(Attributes, "has_attributes is deprecated and will be removed in ActiveFedora 10.0. Instead use:\n property #{fields.first.inspect}, delegate_to: '#{delegate_target}', ...")
155
+
156
+ define_delegated_accessor(fields, delegate_target, options, &block)
156
157
  end
157
158
 
158
159
  # Reveal if the attribute has been declared unique
@@ -171,15 +172,41 @@ module ActiveFedora
171
172
  end
172
173
 
173
174
  def property name, properties={}, &block
175
+ if properties.key?(:predicate)
176
+ define_active_triple_accessor(name, properties, &block)
177
+ elsif properties.key?(:delegate_to)
178
+ define_delegated_accessor([name], properties.delete(:delegate_to), properties.merge(multiple: true), &block)
179
+ else
180
+ raise "You must provide `:datastream' or `:predicate' options to property"
181
+ end
182
+ end
183
+
184
+ private
185
+
186
+ def define_active_triple_accessor(name, properties, &block)
174
187
  warn_duplicate_predicates name, properties
175
188
  properties = { multiple: true }.merge(properties)
176
189
  find_or_create_defined_attribute(name, nil, properties)
177
190
  raise ArgumentError, "#{name} is a keyword and not an acceptable property name." if protected_property_name? name
178
191
  reflection = ActiveFedora::Attributes::PropertyBuilder.build(self, name, properties, &block)
179
192
  ActiveTriples::Reflection.add_reflection self, name, reflection
193
+
194
+ add_attribute_indexing_config(name, &block) if block_given?
180
195
  end
181
196
 
182
- private
197
+ def define_delegated_accessor(fields, delegate_target, options, &block)
198
+ define_attribute_methods fields
199
+ fields.each do |f|
200
+ create_attribute_reader(f, delegate_target, options)
201
+ create_attribute_setter(f, delegate_target, options)
202
+ add_attribute_indexing_config(f, &block) if block_given?
203
+ end
204
+ end
205
+
206
+ def add_attribute_indexing_config(name, &block)
207
+ # TODO the hash can be initalized to return on of these
208
+ index_config[name] ||= ActiveFedora::Indexing::Map::IndexObject.new &block
209
+ end
183
210
 
184
211
  def warn_duplicate_predicates new_name, new_properties
185
212
  new_predicate = new_properties[:predicate]
@@ -19,8 +19,8 @@ module ActiveFedora
19
19
 
20
20
  def changes
21
21
  @changes ||= changed_attributes.each_with_object({}) do |key, result|
22
- if m = /^.*_ids?$/.match(key)
23
- predicate = object.association(m[0].to_sym).reflection.predicate
22
+ if object.respond_to?(:association) && object.association(key.to_sym).present?
23
+ predicate = object.association(key.to_sym).reflection.predicate
24
24
  result[predicate] = graph.query(predicate: predicate)
25
25
  elsif object.class.properties.keys.include?(key)
26
26
  predicate = graph.reflections.reflect_on_property(key).predicate
@@ -0,0 +1,40 @@
1
+ module ActiveFedora
2
+ class CleanConnection < SimpleDelegator
3
+ def get(*args)
4
+ result = __getobj__.get(*args) do |req|
5
+ prefer_headers = Ldp::PreferHeaders.new(req.headers["Prefer"])
6
+ prefer_headers.omit = prefer_headers.omit | omit_uris
7
+ req.headers["Prefer"] = prefer_headers.to_s
8
+ end
9
+ CleanResult.new(result)
10
+ end
11
+
12
+ private
13
+
14
+ def omit_uris
15
+ [
16
+ RDF::Fcrepo4.ServerManaged,
17
+ RDF::Ldp.PreferContainment,
18
+ RDF::Ldp.PreferEmptyContainer,
19
+ RDF::Ldp.PreferMembership
20
+ ]
21
+ end
22
+
23
+ class CleanResult < SimpleDelegator
24
+ def graph
25
+ @graph ||= clean_graph
26
+ end
27
+
28
+ private
29
+
30
+ def clean_graph
31
+ __getobj__.graph.delete(has_model_query)
32
+ __getobj__.graph
33
+ end
34
+
35
+ def has_model_query
36
+ [nil, ActiveFedora::RDF::Fcrepo::Model.hasModel, nil]
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,12 @@
1
+ module ActiveFedora::Core
2
+ class FedoraIdTranslator
3
+ SLASH = '/'.freeze
4
+ def self.call(id)
5
+ id = "/#{id}" unless id.start_with? SLASH
6
+ unless ActiveFedora.fedora.base_path == SLASH || id.start_with?("#{ActiveFedora.fedora.base_path}/")
7
+ id = ActiveFedora.fedora.base_path + id
8
+ end
9
+ ActiveFedora.fedora.host + id
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,9 @@
1
+ module ActiveFedora::Core
2
+ class FedoraUriTranslator
3
+ SLASH = '/'.freeze
4
+ def self.call(uri)
5
+ id = uri.to_s.sub(ActiveFedora.fedora.host + ActiveFedora.fedora.base_path, '')
6
+ id.start_with?(SLASH) ? id[1..-1] : id
7
+ end
8
+ end
9
+ end