active-fedora 3.1.6 → 3.2.0.pre1

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 (44) hide show
  1. data/.gitignore +1 -0
  2. data/Gemfile.lock +22 -22
  3. data/History.txt +9 -3
  4. data/active-fedora.gemspec +3 -3
  5. data/config/predicate_mappings.yml +1 -0
  6. data/config/service_mappings.yml +9 -0
  7. data/lib/active_fedora.rb +7 -1
  8. data/lib/active_fedora/base.rb +84 -30
  9. data/lib/active_fedora/datastream.rb +4 -1
  10. data/lib/active_fedora/datastream_collections.rb +304 -293
  11. data/lib/active_fedora/metadata_datastream.rb +2 -24
  12. data/lib/active_fedora/metadata_datastream_helper.rb +32 -5
  13. data/lib/active_fedora/named_relationships.rb +95 -0
  14. data/lib/active_fedora/nested_attributes.rb +1 -1
  15. data/lib/active_fedora/predicates.rb +76 -0
  16. data/lib/active_fedora/reflection.rb +9 -1
  17. data/lib/active_fedora/relationship.rb +1 -0
  18. data/lib/active_fedora/relationship_graph.rb +152 -0
  19. data/lib/active_fedora/relationships_helper.rb +32 -41
  20. data/lib/active_fedora/rels_ext_datastream.rb +3 -10
  21. data/lib/active_fedora/semantic_node.rb +47 -203
  22. data/lib/active_fedora/service_definitions.rb +89 -0
  23. data/lib/active_fedora/unsaved_digital_object.rb +40 -0
  24. data/lib/active_fedora/version.rb +1 -1
  25. data/spec/integration/base_spec.rb +106 -309
  26. data/spec/integration/datastream_collections_spec.rb +135 -0
  27. data/spec/integration/rels_ext_datastream_spec.rb +14 -35
  28. data/spec/integration/semantic_node_spec.rb +6 -10
  29. data/spec/unit/base_datastream_management_spec.rb +0 -3
  30. data/spec/unit/base_extra_spec.rb +5 -9
  31. data/spec/unit/base_spec.rb +103 -57
  32. data/spec/unit/{base_named_datastream_spec.rb → datastream_collections_spec.rb} +107 -150
  33. data/spec/unit/metadata_datastream_spec.rb +0 -1
  34. data/spec/unit/nokogiri_datastream_spec.rb +0 -1
  35. data/spec/unit/predicates_spec.rb +64 -0
  36. data/spec/unit/qualified_dublin_core_datastream_spec.rb +0 -7
  37. data/spec/unit/relationship_graph_spec.rb +95 -0
  38. data/spec/unit/relationship_spec.rb +4 -4
  39. data/spec/unit/relationships_helper_spec.rb +43 -104
  40. data/spec/unit/rels_ext_datastream_spec.rb +6 -6
  41. data/spec/unit/semantic_node_spec.rb +27 -116
  42. data/spec/unit/service_definitions_spec.rb +52 -0
  43. data/spec/unit/solr_config_options_spec.rb +1 -1
  44. metadata +35 -17
data/.gitignore CHANGED
@@ -26,6 +26,7 @@ pkg
26
26
  #/.rvmrc
27
27
  .yardoc
28
28
  doc
29
+ tmp
29
30
 
30
31
  ## PROJECT::SPECIFIC
31
32
  hydra-jetty
@@ -1,9 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- active-fedora (3.1.6)
5
- activeresource (~> 3.0.0)
6
- activesupport (~> 3.0.0)
4
+ active-fedora (3.2.0.pre1)
5
+ activeresource (>= 3.0.0)
6
+ activesupport (>= 3.0.0)
7
7
  equivalent-xml
8
8
  facets
9
9
  mediashelf-loggable
@@ -13,7 +13,7 @@ PATH
13
13
  om (>= 1.4.4)
14
14
  rdf
15
15
  rdf-rdfxml
16
- rubydora (~> 0.2.6)
16
+ rubydora (~> 0.3.0)
17
17
  solr-ruby (>= 0.0.6)
18
18
  solrizer (> 1.0.0)
19
19
  xml-simple (>= 1.0.12)
@@ -22,23 +22,24 @@ GEM
22
22
  remote: http://rubygems.org/
23
23
  specs:
24
24
  RedCloth (4.2.9)
25
- activemodel (3.0.11)
26
- activesupport (= 3.0.11)
27
- builder (~> 2.1.2)
28
- i18n (~> 0.5.0)
29
- activeresource (3.0.11)
30
- activemodel (= 3.0.11)
31
- activesupport (= 3.0.11)
32
- activesupport (3.0.11)
25
+ activemodel (3.1.3)
26
+ activesupport (= 3.1.3)
27
+ builder (~> 3.0.0)
28
+ i18n (~> 0.6)
29
+ activeresource (3.1.3)
30
+ activemodel (= 3.1.3)
31
+ activesupport (= 3.1.3)
32
+ activesupport (3.1.3)
33
+ multi_json (~> 1.0)
33
34
  addressable (2.2.6)
34
35
  akami (1.0.0)
35
36
  gyoku (>= 0.4.0)
36
37
  archive-tar-minitar (0.5.2)
37
- builder (2.1.2)
38
+ builder (3.0.0)
38
39
  childprocess (0.2.3)
39
40
  ffi (~> 1.0.6)
40
- columnize (0.3.5)
41
- daemons (1.1.4)
41
+ columnize (0.3.6)
42
+ daemons (1.1.5)
42
43
  diff-lcs (1.1.3)
43
44
  equivalent-xml (0.2.8)
44
45
  nokogiri (>= 1.4.3)
@@ -49,7 +50,7 @@ GEM
49
50
  builder (>= 2.1.2)
50
51
  httpi (0.9.5)
51
52
  rack
52
- i18n (0.5.0)
53
+ i18n (0.6.0)
53
54
  jettywrapper (1.2.0)
54
55
  activesupport (>= 3.0.0)
55
56
  childprocess
@@ -66,6 +67,7 @@ GEM
66
67
  mime-types (1.17.2)
67
68
  mocha (0.10.0)
68
69
  metaclass (~> 0.0.1)
70
+ multi_json (1.0.4)
69
71
  multipart-post (1.1.2)
70
72
  nokogiri (1.5.0)
71
73
  nori (1.0.2)
@@ -108,7 +110,7 @@ GEM
108
110
  ruby-debug-base19 (>= 0.11.19)
109
111
  ruby_core_source (0.1.5)
110
112
  archive-tar-minitar (>= 0.5.2)
111
- rubydora (0.2.6)
113
+ rubydora (0.3.0)
112
114
  activemodel
113
115
  activesupport
114
116
  fastercsv
@@ -132,15 +134,13 @@ GEM
132
134
  om (>= 1.4.0)
133
135
  stomp
134
136
  xml-simple
135
- solrizer-fedora (1.2.1)
136
- active-fedora (~> 3.1.0)
137
- activesupport
137
+ solrizer-fedora (1.1.3)
138
+ active-fedora (>= 2.3.0)
138
139
  fastercsv
139
- jettywrapper (>= 1.1.0)
140
140
  rsolr
141
141
  solr-ruby (>= 0.0.6)
142
142
  solrizer (>= 1.0.0)
143
- stomp (1.1.10)
143
+ stomp (1.2.0)
144
144
  wasabi (2.0.0)
145
145
  nokogiri (>= 1.4.0)
146
146
  xml-simple (1.1.1)
@@ -1,6 +1,12 @@
1
- 3.1.6
2
-
3
- HYDRA-733 When serializing, MetadataDatastream does not load the existing content, so it can overwrite with blank
1
+ 3.2.0
2
+
3
+ Don't create pids until save
4
+ inspect and equality methods
5
+ Deprecate datastream_collections
6
+ Rails 3.1 compatibility
7
+ Disseminators have been added
8
+ Adapt To
9
+ ActiveFedora::Relationship is deprecated
4
10
 
5
11
  3.1.5
6
12
  HYDRA-722 updating AF::Base#label= and then saving doesn't persist the change
@@ -22,12 +22,12 @@ Gem::Specification.new do |s|
22
22
  s.add_dependency('nokogiri')
23
23
  s.add_dependency('om', '>= 1.4.4')
24
24
  s.add_dependency('solrizer', '>1.0.0')
25
- s.add_dependency("activeresource", '~> 3.0.0')
26
- s.add_dependency("activesupport", '~> 3.0.0')
25
+ s.add_dependency("activeresource", '>= 3.0.0')
26
+ s.add_dependency("activesupport", '>= 3.0.0')
27
27
  s.add_dependency("mediashelf-loggable")
28
28
  s.add_dependency("equivalent-xml")
29
29
  s.add_dependency("facets")
30
- s.add_dependency("rubydora", '~>0.2.6')
30
+ s.add_dependency("rubydora", '~>0.3.0')
31
31
  s.add_dependency("rdf")
32
32
  s.add_dependency("rdf-rdfxml")
33
33
  s.add_development_dependency("yard")
@@ -41,5 +41,6 @@
41
41
  :is_topic_of: isTopicOf
42
42
  info:fedora/fedora-system:def/model#:
43
43
  :has_model: hasModel
44
+ :has_service: hasService
44
45
  http://www.openarchives.org/OAI/2.0/:
45
46
  :oai_item_id: itemID
@@ -0,0 +1,9 @@
1
+ :service_mapping:
2
+ "fedora-system:3":
3
+ :object_profile: viewObjectProfile
4
+ :method_index: viewMethodIndex
5
+ :item_index: viewItemIndex
6
+ :dc_view: viewDublinCore
7
+ "test:12":
8
+ :document_style_1: getDocumentStyle1
9
+ :document_style_2: getDocumentStyle2
@@ -3,6 +3,7 @@ require 'active_fedora/railtie' if defined? Rails
3
3
  require 'active_support'
4
4
  require 'active_fedora/solr_service'
5
5
  require 'active_fedora/rubydora_connection'
6
+ require 'active_support/core_ext/class/attribute'
6
7
 
7
8
  SOLR_DOCUMENT_ID = ActiveFedora::SolrService.id_field unless defined?(SOLR_DOCUMENT_ID)
8
9
  ENABLE_SOLR_UPDATES = true unless defined?(ENABLE_SOLR_UPDATES)
@@ -16,11 +17,13 @@ module ActiveFedora #:nodoc:
16
17
  autoload :Base
17
18
  autoload :ContentModel
18
19
  autoload :Reflection
19
- autoload :Relationship
20
+ #autoload :Relationship
21
+ autoload :RelationshipGraph
20
22
  autoload :RelationshipsHelper
21
23
  autoload :Datastream
22
24
  autoload :Delegating
23
25
  autoload :DigitalObject
26
+ autoload :UnsavedDigitalObject
24
27
  autoload :Model
25
28
  autoload :MetadataDatastream
26
29
  autoload :MetadataDatastreamHelper
@@ -29,10 +32,13 @@ module ActiveFedora #:nodoc:
29
32
  autoload :QualifiedDublinCoreDatastream
30
33
  autoload :RelsExtDatastream
31
34
  autoload :RelationshipsHelper
35
+ autoload :ServiceDefinitions
32
36
  autoload :SemanticNode
33
37
  autoload :NestedAttributes
34
38
  autoload :FixtureLoader
35
39
  autoload :DatastreamCollections
40
+ autoload :NamedRelationships
41
+ autoload :Predicates
36
42
 
37
43
  end
38
44
 
@@ -3,7 +3,7 @@ require 'nokogiri'
3
3
  require "loggable"
4
4
  require 'active_fedora/datastream_hash'
5
5
 
6
- require 'active_support/core_ext/class/inheritable_attributes'
6
+
7
7
  SOLR_DOCUMENT_ID = "id" unless (defined?(SOLR_DOCUMENT_ID) && !SOLR_DOCUMENT_ID.nil?)
8
8
  ENABLE_SOLR_UPDATES = true unless defined?(ENABLE_SOLR_UPDATES)
9
9
 
@@ -32,7 +32,14 @@ module ActiveFedora
32
32
  class Base
33
33
  include RelationshipsHelper
34
34
  include SemanticNode
35
- class_inheritable_accessor :ds_specs
35
+
36
+ class_attribute :ds_specs
37
+
38
+ def self.inherited(p)
39
+ # each subclass should get a copy of the parent's datastream definitions, it should not add to the parent's definition table.
40
+ p.ds_specs = p.ds_specs.dup
41
+ super
42
+ end
36
43
 
37
44
  self.ds_specs = {'RELS-EXT'=> {:type=> ActiveFedora::RelsExtDatastream, :label=>"", :block=>nil}}
38
45
 
@@ -77,22 +84,19 @@ module ActiveFedora
77
84
  # we configure any defined datastreams.
78
85
  def initialize(attrs = nil)
79
86
  attrs = {} if attrs.nil?
80
- unless attrs[:pid]
81
- if attrs[:namespace]
82
- attrs = attrs.merge!({:pid=>RubydoraConnection.instance.nextid({:namespace=>attrs[:namespace]})})
87
+ attributes = attrs.dup
88
+ @inner_object = attributes.delete(:inner_object)
89
+ unless @inner_object
90
+ if attributes[:pid]
91
+ @inner_object = DigitalObject.find(self.class, attributes[:pid])
83
92
  else
84
- attrs = attrs.merge!({:pid=>RubydoraConnection.instance.nextid})
93
+ @inner_object = UnsavedDigitalObject.new(self.class, attributes.delete(:namespace))
94
+ self.relationships_loaded = true
85
95
  end
86
- self.relationships_loaded = true
87
- @inner_object = DigitalObject.find(self.class, attrs[:pid])
88
- else
89
- @inner_object = DigitalObject.find(self.class, attrs[:pid])
90
- load_datastreams_from_fedora
91
96
  end
92
- configure_defined_datastreams
97
+ load_datastreams
93
98
 
94
- attributes = attrs.dup
95
- [:pid, :namespace, :new_object,:create_date, :modified_date].each { |k| attributes.delete(k)}
99
+ [:pid, :new_object,:create_date, :modified_date].each { |k| attributes.delete(k)}
96
100
  self.attributes=attributes
97
101
  end
98
102
 
@@ -108,6 +112,16 @@ module ActiveFedora
108
112
  ds_specs[args[:name]]= {:type => args[:type], :label => args.fetch(:label,""), :control_group => args.fetch(:control_group,"X"), :disseminator => args.fetch(:disseminator,""), :url => args.fetch(:url,""),:block => block}
109
113
  end
110
114
 
115
+ def self.method_missing (name, args)
116
+ if name == :has_datastream
117
+ ActiveSupport::Deprecation.warn("Deprecation: DatastreamCollections will not be included by default in the next version. To use has_datastream add 'include ActiveFedora::DatastreamCollections' to your model")
118
+ include DatastreamCollections
119
+ has_datastream(args)
120
+ else
121
+ super
122
+ end
123
+
124
+ end
111
125
 
112
126
  def method_missing(name, *args)
113
127
  dsid = corresponding_datastream_name(name)
@@ -142,7 +156,7 @@ module ActiveFedora
142
156
  result = update
143
157
  end
144
158
  self.update_index if @metadata_is_dirty == true && ENABLE_SOLR_UPDATES
145
- @metadata_is_dirty == false
159
+ @metadata_is_dirty = false
146
160
  return result
147
161
  end
148
162
 
@@ -170,6 +184,7 @@ module ActiveFedora
170
184
  end
171
185
 
172
186
  #Fedora::Repository.instance.delete(@inner_object)
187
+ pid = self.pid ## cache so it's still available after delete
173
188
  begin
174
189
  @inner_object.delete
175
190
  rescue RestClient::ResourceNotFound =>e
@@ -202,21 +217,38 @@ module ActiveFedora
202
217
  datastreams
203
218
  end
204
219
 
205
- def load_datastreams_from_fedora
206
- inner_object.datastreams.each do |dsid, datastream|
207
- ds_spec = self.class.ds_specs[dsid]
208
- datastreams[dsid] = datastream
209
- if (ds_spec)
210
- klass = ds_spec[:type]
211
- datastreams[dsid].model = self if klass == RelsExtDatastream
212
-
213
- if ds_spec[:block].class == Proc
214
- ds_spec[:block].call(datastreams[dsid])
215
- end
220
+ def configure_datastream(ds, ds_spec=nil)
221
+ ds_spec ||= self.class.ds_specs[ds.instance_variable_get(:@dsid)]
222
+ if ds_spec
223
+ ds.model = self if ds_spec[:type] == RelsExtDatastream
224
+ # If you called has_metadata with a block, pass the block into the Datastream class
225
+ if ds_spec[:block].class == Proc
226
+ ds_spec[:block].call(ds)
216
227
  end
217
228
  end
218
229
  end
219
230
 
231
+ def datastream_from_spec(ds_spec, name)
232
+ ds = ds_spec[:type].new(inner_object, name)
233
+ ds.dsLabel = ds_spec[:label] if ds_spec[:label].present?
234
+ ds.controlGroup = ds_spec[:control_group]
235
+ additional_attributes_for_external_and_redirect_control_groups(ds, ds_spec)
236
+ ds
237
+ end
238
+
239
+ def load_datastreams
240
+ ds_specs = self.class.ds_specs.dup
241
+ inner_object.datastreams.each do |dsid, ds|
242
+ self.add_datastream(ds)
243
+ configure_datastream(datastreams[dsid])
244
+ ds_specs.delete(dsid)
245
+ end
246
+ ds_specs.each do |name,ds_spec|
247
+ ds = datastream_from_spec(ds_spec, name)
248
+ self.add_datastream(ds)
249
+ configure_datastream(ds, ds_spec)
250
+ end
251
+ end
220
252
 
221
253
  # Adds datastream to the object. Saves the datastream to fedora upon adding.
222
254
  # If datastream does not have a DSID, a unique DSID is generated
@@ -241,7 +273,7 @@ module ActiveFedora
241
273
  results = []
242
274
  datastreams.each_value do |ds|
243
275
  if ds.kind_of?(ActiveFedora::MetadataDatastream) || ds.kind_of?(ActiveFedora::NokogiriDatastream)
244
- results<<ds
276
+ results << ds
245
277
  end
246
278
  end
247
279
  return results
@@ -255,7 +287,7 @@ module ActiveFedora
255
287
  if !ds.kind_of?(ActiveFedora::MetadataDatastream)
256
288
  dsid = ds.dsid
257
289
  if dsid != "DC" && dsid != "RELS-EXT"
258
- results<<ds
290
+ results << ds
259
291
  end
260
292
  end
261
293
  end
@@ -426,7 +458,7 @@ module ActiveFedora
426
458
  # if there is no fedora object (loaded from solr) get the instance var
427
459
  # TODO make inner_object a proxy that can hold the pid
428
460
  def pid
429
- @pid ||= @inner_object.pid
461
+ @inner_object.pid
430
462
  # @inner_object ? @inner_object.pid : @pid
431
463
  end
432
464
 
@@ -517,6 +549,17 @@ module ActiveFedora
517
549
  return xml.to_s
518
550
  end
519
551
 
552
+ def ==(comparison_object)
553
+ comparison_object.equal?(self) ||
554
+ (comparison_object.instance_of?(self.class) &&
555
+ comparison_object.pid == pid &&
556
+ !comparison_object.new_record?)
557
+ end
558
+
559
+ def inspect
560
+ "#<#{self.class}:#{self.hash} @pid=\"#{pid}\" >"
561
+ end
562
+
520
563
  # Return a Hash representation of this object where keys in the hash are appropriate Solr field names.
521
564
  # @param [Hash] solr_doc (optional) Hash to insert the fields into
522
565
  # @param [Hash] opts (optional)
@@ -551,6 +594,15 @@ module ActiveFedora
551
594
  end
552
595
 
553
596
 
597
+ # ** EXPERIMENTAL **
598
+ # This method adapts the inner_object to a new ActiveFedora::Base implementation
599
+ # This is intended to minimize redundant interactions with Fedora
600
+ def adapt_to(klass)
601
+ unless klass.ancestors.include? ActiveFedora::Base
602
+ raise "Cannot adapt #{self.class.name} to #{klass.name}: Not a ActiveFedora::Base subclass"
603
+ end
604
+ klass.new({:inner_object=>inner_object})
605
+ end
554
606
  # ** EXPERIMENTAL **
555
607
  #
556
608
  # This method can be used instead of ActiveFedora::Model::ClassMethods.load_instance.
@@ -734,6 +786,7 @@ module ActiveFedora
734
786
 
735
787
  # Deals with preparing new object to be saved to Fedora, then pushes it and its datastreams into Fedora.
736
788
  def create
789
+ @inner_object = @inner_object.save #replace the unsaved digital object with a saved digital object
737
790
  assert_content_model
738
791
  @metadata_is_dirty = true
739
792
  update
@@ -767,7 +820,8 @@ module ActiveFedora
767
820
  include Associations
768
821
  include NestedAttributes
769
822
  include Reflection
770
- include DatastreamCollections
823
+ include NamedRelationships
824
+ # include DatastreamCollections
771
825
  end
772
826
 
773
827
  end
@@ -3,6 +3,7 @@ module ActiveFedora
3
3
  #This class represents a Fedora datastream
4
4
  class Datastream < Rubydora::Datastream
5
5
 
6
+ attr_writer :digital_object
6
7
  attr_accessor :dirty, :last_modified, :fields
7
8
  before_create :add_mime_type
8
9
 
@@ -28,6 +29,7 @@ module ActiveFedora
28
29
  end
29
30
 
30
31
  # Test whether this datastream been modified since it was last saved?
32
+ # TODO deprecate this, just use changed?
31
33
  def dirty?
32
34
  @dirty || changed?
33
35
  end
@@ -37,7 +39,8 @@ module ActiveFedora
37
39
  end
38
40
 
39
41
  def save
40
- raise "No content #{dsid}" if @content.nil?
42
+ #raise "No content #{dsid}" if @content.nil?
43
+ return if @content.nil?
41
44
  run_callbacks :save do
42
45
  return create if new?
43
46
  repository.modify_datastream to_api_params.merge({ :pid => pid, :dsid => dsid })
@@ -1,326 +1,337 @@
1
- module DatastreamCollections
2
- extend ActiveSupport::Concern
1
+ require 'active_support/core_ext/module/aliasing'
2
+ module ActiveFedora
3
+ module DatastreamCollections
4
+ extend ActiveSupport::Concern
3
5
 
4
- included do
5
- class_inheritable_accessor :class_named_datastreams_desc
6
- self.class_named_datastreams_desc = {}
7
- end
6
+ included do
7
+ class_attribute :class_named_datastreams_desc
8
+ self.class_named_datastreams_desc = {}
9
+ class << self
10
+ def inherited_with_datastream_collections(kls) #:nodoc:
11
+ ## Do some inheritance logic that doesn't override Base.inherited
12
+ inherited_without_datastream_collections kls
13
+ kls.class_named_datastreams_desc = kls.class_named_datastreams_desc.dup
14
+ end
15
+ alias_method_chain :inherited, :datastream_collections
16
+ end
17
+ end
8
18
 
9
- module ClassMethods
19
+ module ClassMethods
10
20
 
11
- # ** EXPERIMENTAL **
12
- #
13
- # Allows for a datastream to be treated like any other attribute of a model class
14
- # while enforcing mimeType and/or datastream type (ie. external, managed, etc.) if defined.
15
- # ====Examples
16
- #
17
- # has_datastream :name=>"thumbnails",:prefix => "THUMB",:type=>ActiveFedora::Datastream, :mimeType=>"image/jpeg", :controlGroup=>'M'
18
- # has_datastream :name=>"EADs", :type=>ActiveFedora::Datastream, :mimeType=>"application/xml", :controlGroup=>'M'
19
- # has_datastream :name=>"external_images", :type=>ActiveFedora::Datastream, :controlGroup=>'E'
20
- #
21
- # Required Keys in args
22
- # :name - name to give this datastream (must be unique)
23
- #
24
- # Optional Keys in args
25
- # :prefix - used to create the DSID plus an index ie. THUMB1, THUMB2. If :prefix is not specified, defaults to :name value in all uppercase
26
- # :type - defaults to ActiveFedora::Datastream if you would like content specific class to be used supply it here
27
- # :mimeType - if supplied it will ensure any datastreams added are of this type, if not supplied any mimeType is acceptabl e
28
- # :controlGroup - possible values "X", "M", "R", or "E" (InlineXML, Managed Content, Redirect, or External Referenced) If controlGroup is 'E' or 'R' it expects a dsLocation be defined when adding the datastream.
29
- #
30
- # You use the datastream attribute using helper methods created for each datastream name:
31
- #
32
- # ====Helper Method Examples
33
- # thumbnails_append - Append a thumbnail datastream
34
- # thumbnails - Get array of thumbnail datastreams
35
- # thumbnails_ids - Get array of dsid's for thumbnail datastreams
36
- #
37
- # When loading the list of datastreams for a name from Fedora it uses the DSID prefix to find them in Fedora
38
- def has_datastream(args)
39
- unless args.has_key?(:name)
40
- return false
41
- end
42
- unless args.has_key?(:prefix)
43
- args.merge!({:prefix=>args[:name].to_s.upcase})
44
- end
45
- unless class_named_datastreams_desc.has_key?(args[:name])
46
- class_named_datastreams_desc[args[:name]] = {}
21
+ # ** EXPERIMENTAL **
22
+ #
23
+ # Allows for a datastream to be treated like any other attribute of a model class
24
+ # while enforcing mimeType and/or datastream type (ie. external, managed, etc.) if defined.
25
+ # ====Examples
26
+ #
27
+ # has_datastream :name=>"thumbnails",:prefix => "THUMB",:type=>ActiveFedora::Datastream, :mimeType=>"image/jpeg", :controlGroup=>'M'
28
+ # has_datastream :name=>"EADs", :type=>ActiveFedora::Datastream, :mimeType=>"application/xml", :controlGroup=>'M'
29
+ # has_datastream :name=>"external_images", :type=>ActiveFedora::Datastream, :controlGroup=>'E'
30
+ #
31
+ # Required Keys in args
32
+ # :name - name to give this datastream (must be unique)
33
+ #
34
+ # Optional Keys in args
35
+ # :prefix - used to create the DSID plus an index ie. THUMB1, THUMB2. If :prefix is not specified, defaults to :name value in all uppercase
36
+ # :type - defaults to ActiveFedora::Datastream if you would like content specific class to be used supply it here
37
+ # :mimeType - if supplied it will ensure any datastreams added are of this type, if not supplied any mimeType is acceptabl e
38
+ # :controlGroup - possible values "X", "M", "R", or "E" (InlineXML, Managed Content, Redirect, or External Referenced) If controlGroup is 'E' or 'R' it expects a dsLocation be defined when adding the datastream.
39
+ #
40
+ # You use the datastream attribute using helper methods created for each datastream name:
41
+ #
42
+ # ====Helper Method Examples
43
+ # thumbnails_append - Append a thumbnail datastream
44
+ # thumbnails - Get array of thumbnail datastreams
45
+ # thumbnails_ids - Get array of dsid's for thumbnail datastreams
46
+ #
47
+ # When loading the list of datastreams for a name from Fedora it uses the DSID prefix to find them in Fedora
48
+ def has_datastream(args)
49
+ unless args.has_key?(:name)
50
+ return false
51
+ end
52
+ unless args.has_key?(:prefix)
53
+ args.merge!({:prefix=>args[:name].to_s.upcase})
54
+ end
55
+ unless class_named_datastreams_desc.has_key?(args[:name])
56
+ class_named_datastreams_desc[args[:name]] = {}
57
+ end
58
+
59
+ args.merge!({:mimeType=>args[:mime_type]}) if args.has_key?(:mime_type)
60
+
61
+ unless class_named_datastreams_desc[args[:name]].has_key?(:type)
62
+ #default to type ActiveFedora::Datastream
63
+ args.merge!({:type => "ActiveFedora::Datastream"})
64
+ end
65
+ class_named_datastreams_desc[args[:name]]= args
66
+ create_named_datastream_finders(args[:name],args[:prefix])
67
+ create_named_datastream_update_methods(args[:name])
47
68
  end
48
-
49
- args.merge!({:mimeType=>args[:mime_type]}) if args.has_key?(:mime_type)
50
69
 
51
- unless class_named_datastreams_desc[args[:name]].has_key?(:type)
52
- #default to type ActiveFedora::Datastream
53
- args.merge!({:type => "ActiveFedora::Datastream"})
54
- end
55
- class_named_datastreams_desc[args[:name]]= args
56
- create_named_datastream_finders(args[:name],args[:prefix])
57
- create_named_datastream_update_methods(args[:name])
58
- end
59
-
60
- # ** EXPERIMENTAL **
61
- #
62
- # Creates the following helper methods for a datastream name
63
- # [datastream_name]_append - Add a named datastream
64
- #
65
- # ==== Examples for "thumbnails" datastream
66
- # thumbnails_append - Append a thumbnail datastream
67
- # TODO: Add [datastream_name]_remove
68
- def create_named_datastream_update_methods(name)
69
- append_file_method_name = "#{name.to_s.downcase}_file_append"
70
- append_method_name = "#{name.to_s.downcase}_append"
71
- #remove_method_name = "#{name.to_s.downcase}_remove"
72
- self.send(:define_method,:"#{append_file_method_name}") do |*args|
73
- file,opts = *args
74
- opts ||= {}
75
- add_named_file_datastream(name,file,opts)
76
- end
70
+ # ** EXPERIMENTAL **
71
+ #
72
+ # Creates the following helper methods for a datastream name
73
+ # [datastream_name]_append - Add a named datastream
74
+ #
75
+ # ==== Examples for "thumbnails" datastream
76
+ # thumbnails_append - Append a thumbnail datastream
77
+ # TODO: Add [datastream_name]_remove
78
+ def create_named_datastream_update_methods(name)
79
+ append_file_method_name = "#{name.to_s.downcase}_file_append"
80
+ append_method_name = "#{name.to_s.downcase}_append"
81
+ #remove_method_name = "#{name.to_s.downcase}_remove"
82
+ self.send(:define_method,:"#{append_file_method_name}") do |*args|
83
+ file,opts = *args
84
+ opts ||= {}
85
+ add_named_file_datastream(name,file,opts)
86
+ end
87
+
88
+ self.send(:define_method,:"#{append_method_name}") do |*args|
89
+ #call add_named_datastream instead of add_file_named_datastream in case not managed datastream
90
+ add_named_datastream(name,*args)
91
+ end
92
+ end
77
93
 
78
- self.send(:define_method,:"#{append_method_name}") do |*args|
79
- #call add_named_datastream instead of add_file_named_datastream in case not managed datastream
80
- add_named_datastream(name,*args)
81
- end
82
- end
83
-
84
- # ** EXPERIMENTAL **
85
- #
86
- # Creates the following helper methods for a datastream name
87
- # [datastream_name] - Returns array of named datastreams
88
- # [datastream_name]_ids - Returns array of named datastream dsids
89
- #
90
- # ==== Examples for "thumbnails" datastream
91
- # thumbnails - Get array of thumbnail datastreams
92
- # thumbnails_ids - Get array of dsid's for thumbnail datastreams
93
- def create_named_datastream_finders(name, prefix)
94
- class_eval <<-END, __FILE__, __LINE__
95
- def #{name}(opts={})
96
- id_array = []
97
- keys = datastreams.keys
98
- id_array = keys.select {|v| v =~ /#{prefix}\d*/}
99
- if opts[:response_format] == :id_array
100
- return id_array
101
- else
102
- named_ds = []
103
- id_array.each do |name|
104
- if datastreams.has_key?(name)
105
- named_ds.push(datastreams[name])
94
+ # ** EXPERIMENTAL **
95
+ #
96
+ # Creates the following helper methods for a datastream name
97
+ # [datastream_name] - Returns array of named datastreams
98
+ # [datastream_name]_ids - Returns array of named datastream dsids
99
+ #
100
+ # ==== Examples for "thumbnails" datastream
101
+ # thumbnails - Get array of thumbnail datastreams
102
+ # thumbnails_ids - Get array of dsid's for thumbnail datastreams
103
+ def create_named_datastream_finders(name, prefix)
104
+ class_eval <<-END, __FILE__, __LINE__
105
+ def #{name}(opts={})
106
+ id_array = []
107
+ keys = datastreams.keys
108
+ id_array = keys.select {|v| v =~ /#{prefix}\d*/}
109
+ if opts[:response_format] == :id_array
110
+ return id_array
111
+ else
112
+ named_ds = []
113
+ id_array.each do |name|
114
+ if datastreams.has_key?(name)
115
+ named_ds.push(datastreams[name])
116
+ end
106
117
  end
118
+ return named_ds
107
119
  end
108
- return named_ds
109
120
  end
121
+ def #{name}_ids
122
+ #{name}(:response_format => :id_array)
123
+ end
124
+ END
110
125
  end
111
- def #{name}_ids
112
- #{name}(:response_format => :id_array)
113
- end
114
- END
115
- end
116
-
117
-
126
+
118
127
 
119
- end
120
128
 
121
- # ** EXPERIMENTAL **
122
- #
123
- # Accessor for class variable for hash that stores arguments passed to has_datastream calls within an
124
- # ActiveFedora::Base child class.
125
- #
126
- # has_datastream :name=>"audio_file", :prefix=>"AUDIO", :type=>ActiveFedora::Datastream, :mimeType=>"audio/x-wav"
127
- # has_datastream :name=>"external_images", :prefix=>"EXTIMG", :type=>ActiveFedora::Datastream,:mimeType=>"image/jpeg", :controlGroup=>'E'
128
- #
129
- # The above examples result in the following hash
130
- # {"audio_file"=>{:prefix=>"AUDIO",:type=>ActiveFedora::Datastream, :mimeType=>"audio/x-wav", :controlGroup=>'M'},
131
- # "external_images=>{:prefix=>"EXTIMG", :type=>ActiveFedora::Datastream,:mimeType=>"image/jpeg", :controlGroup=>'E'}}
132
- #
133
- # This hash is later used when adding a named datastream such as an "audio_file" as defined above.
134
- def named_datastreams_desc
135
- self.class_named_datastreams_desc ||= {}
136
129
  end
137
130
 
138
- # ** EXPERIMENTAL **
139
- #
140
- # Returns array of datastream names defined for this object
141
- def datastream_names
142
- named_datastreams_desc.keys
143
- end
144
-
145
- # ** EXPERIMENTAL **
146
- #
147
- # Calls add_named_datastream while assuming it will be managed content and sets :blob and :controlGroup values accordingly
148
- # ====Parameters
149
- # name: Datastream name
150
- # file: The file to add for this datastream
151
- # opts: Options hash. See +add_named_datastream+ for expected keys and values
152
- def add_named_file_datastream(name, file, opts={})
153
- opts.merge!({:blob=>file,:controlGroup=>'M'})
154
- add_named_datastream(name,opts)
155
- end
156
-
157
- # ** EXPERIMENTAL **
158
- #
159
- # This object is used by [datastream_name]_append helper to add a named datastream
160
- # but can also be called directly.
161
- # ====Parameters
162
- # name: name of datastream to add
163
- # opts: hash defining datastream attributes
164
- # The following are expected keys in opts hash:
165
- # :label => Defaults to the file name
166
- # :blob or :file => Required to point to the datastream file being added if managed content
167
- # :controlGroup => defaults to 'M' for managed, can also be 'E' external and 'R' for redirected
168
- # :content_type => required if the file does not respond to 'content_type' and should match :mimeType in has_datastream definition if defined
169
- # :dsLocation => holds uri location of datastream. Required only if :controlGroup is type 'E' or 'R'.
170
- # :dsid or :dsId => Optional, and used to update an existing datastream with dsid supplied. Will throw an error if dsid does not exist and does not match prefix pattern for datastream name
171
- def add_named_datastream(name,opts={})
172
- unless named_datastreams_desc.has_key?(name) && named_datastreams_desc[name].has_key?(:type)
173
- raise "Failed to add datastream. Named datastream #{name} not defined for object #{pid}."
131
+ # ** EXPERIMENTAL **
132
+ #
133
+ # Accessor for class variable for hash that stores arguments passed to has_datastream calls within an
134
+ # ActiveFedora::Base child class.
135
+ #
136
+ # has_datastream :name=>"audio_file", :prefix=>"AUDIO", :type=>ActiveFedora::Datastream, :mimeType=>"audio/x-wav"
137
+ # has_datastream :name=>"external_images", :prefix=>"EXTIMG", :type=>ActiveFedora::Datastream,:mimeType=>"image/jpeg", :controlGroup=>'E'
138
+ #
139
+ # The above examples result in the following hash
140
+ # {"audio_file"=>{:prefix=>"AUDIO",:type=>ActiveFedora::Datastream, :mimeType=>"audio/x-wav", :controlGroup=>'M'},
141
+ # "external_images=>{:prefix=>"EXTIMG", :type=>ActiveFedora::Datastream,:mimeType=>"image/jpeg", :controlGroup=>'E'}}
142
+ #
143
+ # This hash is later used when adding a named datastream such as an "audio_file" as defined above.
144
+ def named_datastreams_desc
145
+ self.class_named_datastreams_desc ||= {}
174
146
  end
175
147
 
176
- if opts.has_key?(:mime_type)
177
- opts.merge!({:content_type=>opts[:mime_type]})
178
- elsif opts.has_key?(:mimeType)
179
- opts.merge!({:content_type=>opts[:mimeType]})
148
+ # ** EXPERIMENTAL **
149
+ #
150
+ # Returns array of datastream names defined for this object
151
+ def datastream_names
152
+ named_datastreams_desc.keys
180
153
  end
181
- opts.merge!(named_datastreams_desc[name])
182
-
183
- label = opts.has_key?(:label) ? opts[:label] : ""
154
+
155
+ # ** EXPERIMENTAL **
156
+ #
157
+ # Calls add_named_datastream while assuming it will be managed content and sets :blob and :controlGroup values accordingly
158
+ # ====Parameters
159
+ # name: Datastream name
160
+ # file: The file to add for this datastream
161
+ # opts: Options hash. See +add_named_datastream+ for expected keys and values
162
+ def add_named_file_datastream(name, file, opts={})
163
+ opts.merge!({:blob=>file,:controlGroup=>'M'})
164
+ add_named_datastream(name,opts)
165
+ end
166
+
167
+ # ** EXPERIMENTAL **
168
+ #
169
+ # This object is used by [datastream_name]_append helper to add a named datastream
170
+ # but can also be called directly.
171
+ # ====Parameters
172
+ # name: name of datastream to add
173
+ # opts: hash defining datastream attributes
174
+ # The following are expected keys in opts hash:
175
+ # :label => Defaults to the file name
176
+ # :blob or :file => Required to point to the datastream file being added if managed content
177
+ # :controlGroup => defaults to 'M' for managed, can also be 'E' external and 'R' for redirected
178
+ # :content_type => required if the file does not respond to 'content_type' and should match :mimeType in has_datastream definition if defined
179
+ # :dsLocation => holds uri location of datastream. Required only if :controlGroup is type 'E' or 'R'.
180
+ # :dsid or :dsId => Optional, and used to update an existing datastream with dsid supplied. Will throw an error if dsid does not exist and does not match prefix pattern for datastream name
181
+ def add_named_datastream(name,opts={})
182
+ unless named_datastreams_desc.has_key?(name) && named_datastreams_desc[name].has_key?(:type)
183
+ raise "Failed to add datastream. Named datastream #{name} not defined for object #{pid}."
184
+ end
184
185
 
185
- #only do these steps for managed datastreams
186
- unless (opts.has_key?(:controlGroup)&&opts[:controlGroup]!="M")
187
- if opts.has_key?(:file)
188
- opts.merge!({:blob => opts[:file]})
189
- opts.delete(:file)
186
+ if opts.has_key?(:mime_type)
187
+ opts.merge!({:content_type=>opts[:mime_type]})
188
+ elsif opts.has_key?(:mimeType)
189
+ opts.merge!({:content_type=>opts[:mimeType]})
190
+ end
191
+ opts.merge!(named_datastreams_desc[name])
192
+
193
+ label = opts.has_key?(:label) ? opts[:label] : ""
194
+
195
+ #only do these steps for managed datastreams
196
+ unless (opts.has_key?(:controlGroup)&&opts[:controlGroup]!="M")
197
+ if opts.has_key?(:file)
198
+ opts.merge!({:blob => opts[:file]})
199
+ opts.delete(:file)
200
+ end
201
+
202
+ raise "You must define parameter blob for this managed datastream to load for #{pid}" unless opts.has_key?(:blob)
203
+
204
+ #if no explicit label and is a file use original file name for label
205
+ if !opts.has_key?(:label)&&opts[:blob].respond_to?(:original_filename)
206
+ label = opts[:blob].original_filename
207
+ end
208
+
209
+ if opts[:blob].respond_to?(:content_type)&&!opts[:blob].content_type.nil? && !opts.has_key?(:content_type)
210
+ opts.merge!({:content_type=>opts[:blob].content_type})
211
+ end
212
+
213
+ raise "The blob must respond to content_type or the hash must have :content_type or :mime_type property set" unless opts.has_key?(:content_type)
214
+
215
+ #throw error for mimeType mismatch
216
+ if named_datastreams_desc[name].has_key?(:mimeType) && !named_datastreams_desc[name][:mimeType].eql?(opts[:content_type])
217
+ raise "Content type mismatch for add datastream #{name} to #{pid}. Expected: #{named_datastreams_desc[name][:mimeType]}, Actual: #{opts[:content_type]}"
218
+ end
219
+ else
220
+ label = opts[:dsLocation] if (opts.has_key?(:dsLocation))
190
221
  end
191
222
 
192
- raise "You must define parameter blob for this managed datastream to load for #{pid}" unless opts.has_key?(:blob)
223
+ opts.merge!(:dsLabel => label)
193
224
 
194
- #if no explicit label and is a file use original file name for label
195
- if !opts.has_key?(:label)&&opts[:blob].respond_to?(:original_filename)
196
- label = opts[:blob].original_filename
225
+ ds = create_datastream(named_datastreams_desc[name][:type], opts[:dsid], opts)
226
+ #Must be of type datastream
227
+ assert_kind_of 'datastream', ds, ActiveFedora::Datastream
228
+ #make sure dsid is nil so that it uses the prefix for mapping purposes
229
+ #check dsid works for the prefix if it is set
230
+ if !ds.dsid.nil? && opts.has_key?(:prefix)
231
+ raise "dsid supplied does not conform to pattern #{opts[:prefix]}[number]" unless ds.dsid =~ /#{opts[:prefix]}[0-9]/
197
232
  end
198
233
 
199
- if opts[:blob].respond_to?(:content_type)&&!opts[:blob].content_type.nil? && !opts.has_key?(:content_type)
200
- opts.merge!({:content_type=>opts[:blob].content_type})
201
- end
234
+ add_datastream(ds,opts)
235
+ end
202
236
 
203
- raise "The blob must respond to content_type or the hash must have :content_type or :mime_type property set" unless opts.has_key?(:content_type)
204
-
205
- #throw error for mimeType mismatch
206
- if named_datastreams_desc[name].has_key?(:mimeType) && !named_datastreams_desc[name][:mimeType].eql?(opts[:content_type])
207
- raise "Content type mismatch for add datastream #{name} to #{pid}. Expected: #{named_datastreams_desc[name][:mimeType]}, Actual: #{opts[:content_type]}"
208
- end
209
- else
210
- label = opts[:dsLocation] if (opts.has_key?(:dsLocation))
237
+ # ** EXPERIMENTAL **
238
+ #
239
+ # Update an existing named datastream. It has same parameters as add_named_datastream
240
+ # except the :dsid key is now required.
241
+ #
242
+ # ====TODO
243
+ # Currently requires you to update file if a managed datastream
244
+ # but could change to allow metadata only updates as well
245
+ def update_named_datastream(name, opts={})
246
+ #check that dsid provided matches existing datastream with that name
247
+ raise "You must define parameter dsid for datastream to update for #{pid}" unless opts.include?(:dsid)
248
+ raise "Datastream with name #{name} and dsid #{opts[:dsid]} does not exist for #{pid}" unless self.send("#{name}_ids").include?(opts[:dsid])
249
+ add_named_datastream(name,opts)
211
250
  end
212
251
 
213
- opts.merge!(:dsLabel => label)
214
-
215
- ds = create_datastream(named_datastreams_desc[name][:type], opts[:dsid], opts)
216
- #Must be of type datastream
217
- assert_kind_of 'datastream', ds, ActiveFedora::Datastream
218
- #make sure dsid is nil so that it uses the prefix for mapping purposes
219
- #check dsid works for the prefix if it is set
220
- if !ds.dsid.nil? && opts.has_key?(:prefix)
221
- raise "dsid supplied does not conform to pattern #{opts[:prefix]}[number]" unless ds.dsid =~ /#{opts[:prefix]}[0-9]/
252
+ # ** EXPERIMENTAL **
253
+ #
254
+ # Throws an assertion failure unless the object 'o' is kind_of? class 't'
255
+ # ====Parameters
256
+ # n: Name of object
257
+ # o: The object to test
258
+ # t: The class type to check is kind_of?
259
+ def assert_kind_of(n, o,t)
260
+ raise "Assertion failure: #{n}: #{o} is not of type #{t}" unless o.kind_of?(t)
222
261
  end
223
262
 
224
- add_datastream(ds,opts)
225
- end
226
-
227
- # ** EXPERIMENTAL **
228
- #
229
- # Update an existing named datastream. It has same parameters as add_named_datastream
230
- # except the :dsid key is now required.
231
- #
232
- # ====TODO
233
- # Currently requires you to update file if a managed datastream
234
- # but could change to allow metadata only updates as well
235
- def update_named_datastream(name, opts={})
236
- #check that dsid provided matches existing datastream with that name
237
- raise "You must define parameter dsid for datastream to update for #{pid}" unless opts.include?(:dsid)
238
- raise "Datastream with name #{name} and dsid #{opts[:dsid]} does not exist for #{pid}" unless self.send("#{name}_ids").include?(opts[:dsid])
239
- add_named_datastream(name,opts)
240
- end
241
-
242
- # ** EXPERIMENTAL **
243
- #
244
- # Throws an assertion failure unless the object 'o' is kind_of? class 't'
245
- # ====Parameters
246
- # n: Name of object
247
- # o: The object to test
248
- # t: The class type to check is kind_of?
249
- def assert_kind_of(n, o,t)
250
- raise "Assertion failure: #{n}: #{o} is not of type #{t}" unless o.kind_of?(t)
251
- end
252
-
253
- # ** EXPERIMENTAL **
254
- #
255
- # Returns true if the name is a defined named datastream
256
- def is_named_datastream?(name)
257
- named_datastreams_desc.has_key?(name)
258
- end
263
+ # ** EXPERIMENTAL **
264
+ #
265
+ # Returns true if the name is a defined named datastream
266
+ def is_named_datastream?(name)
267
+ named_datastreams_desc.has_key?(name)
268
+ end
259
269
 
260
- # ** EXPERIMENTAL **
261
- #
262
- # Returns hash of datastream names defined by has_datastream calls mapped to
263
- # array of datastream objects that have been added
264
- # ====Example
265
- # For the following has_datastream entries and a datastream defined for minivan only would be
266
- # has_datastream :name=>"minivan", :prefix => "VAN", :type=>ActiveFedora::Datastream,:mimeType=>"image/jpeg", :controlGroup=>'M'
267
- # has_datastream :name=>"external_images", :prefix=>"EXTIMG", :type=>ActiveFedora::Datastream,:mimeType=>"image/jpeg", :controlGroup=>'E'
268
- #
269
- # Returns
270
- # {"external_images"=>[],"thumbnails"=>{#<ActiveFedora::Datastream:0x7ffd6512daf8 ...}}
271
- def named_datastreams
272
- ds_values = {}
273
- self.class.class_named_datastreams_desc.keys.each do |name|
274
- ds_values.merge!({name=>self.send("#{name}")})
270
+ # ** EXPERIMENTAL **
271
+ #
272
+ # Returns hash of datastream names defined by has_datastream calls mapped to
273
+ # array of datastream objects that have been added
274
+ # ====Example
275
+ # For the following has_datastream entries and a datastream defined for minivan only would be
276
+ # has_datastream :name=>"minivan", :prefix => "VAN", :type=>ActiveFedora::Datastream,:mimeType=>"image/jpeg", :controlGroup=>'M'
277
+ # has_datastream :name=>"external_images", :prefix=>"EXTIMG", :type=>ActiveFedora::Datastream,:mimeType=>"image/jpeg", :controlGroup=>'E'
278
+ #
279
+ # Returns
280
+ # {"external_images"=>[],"thumbnails"=>{#<ActiveFedora::Datastream:0x7ffd6512daf8 ...}}
281
+ def named_datastreams
282
+ ds_values = {}
283
+ self.class.class_named_datastreams_desc.keys.each do |name|
284
+ ds_values.merge!({name=>self.send("#{name}")})
285
+ end
286
+ return ds_values
275
287
  end
276
- return ds_values
277
- end
278
-
279
- # ** EXPERIMENTAL **
280
- #
281
- # Returns hash of datastream names mapped to an array
282
- # of dsid's for named datastream objects
283
- # === Example
284
- # For the following has_datastream call, assume we have added two datastreams.
285
- #
286
- # has_datastream :name=>"thumbnails",:prefix => "THUMB",:type=>ActiveFedora::Datastream, :mimeType=>"image/jpeg", :controlGroup=>'M'
287
- #
288
- # It would then return
289
- # {"thumbnails=>["THUMB1", "THUMB2"]}
290
- def named_datastreams_ids
291
- dsids = {}
292
- self.class.class_named_datastreams_desc.keys.each do |name|
293
- dsid_array = self.send("#{name}_ids")
294
- dsids[name] = dsid_array
288
+
289
+ # ** EXPERIMENTAL **
290
+ #
291
+ # Returns hash of datastream names mapped to an array
292
+ # of dsid's for named datastream objects
293
+ # === Example
294
+ # For the following has_datastream call, assume we have added two datastreams.
295
+ #
296
+ # has_datastream :name=>"thumbnails",:prefix => "THUMB",:type=>ActiveFedora::Datastream, :mimeType=>"image/jpeg", :controlGroup=>'M'
297
+ #
298
+ # It would then return
299
+ # {"thumbnails=>["THUMB1", "THUMB2"]}
300
+ def named_datastreams_ids
301
+ dsids = {}
302
+ self.class.class_named_datastreams_desc.keys.each do |name|
303
+ dsid_array = self.send("#{name}_ids")
304
+ dsids[name] = dsid_array
305
+ end
306
+ return dsids
307
+ end
308
+
309
+ # ** EXPERIMENTAL **
310
+ #
311
+ # Returns the hash that stores arguments passed to has_datastream calls within an
312
+ # ActiveFedora::Base child class.
313
+ #
314
+ # has_datastream :name=>"audio_file", :prefix=>"AUDIO", :type=>ActiveFedora::Datastream, :mimeType=>"audio/x-wav"
315
+ # has_datastream :name=>"external_images", :prefix=>"EXTIMG", :type=>ActiveFedora::Datastream,:mimeType=>"image/jpeg", :controlGroup=>'E'
316
+ #
317
+ # The above examples result in the following hash
318
+ # {"audio_file"=>{:prefix=>"AUDIO",:type=>ActiveFedora::Datastream, :mimeType=>"audio/x-wav", :controlGroup=>'M'},
319
+ # "external_images=>{:prefix=>"EXTIMG", :type=>ActiveFedora::Datastream,:mimeType=>"image/jpeg", :controlGroup=>'E'}}
320
+ #
321
+ # This hash is later used when adding a named datastream such as an "audio_file" as defined above.
322
+ def named_datastreams_desc
323
+ @named_datastreams_desc ||= self.class.class_named_datastreams_desc
324
+ end
325
+
326
+ # ** EXPERIMENTAL **
327
+ #
328
+ # Get class variable hash that stores has_datastream arguments.
329
+ # It is used to initialize the value returned by public named_datastreams_desc method
330
+ # Deprecated
331
+ def named_datastreams_desc_from_class
332
+ logger.warn "named_datastreams_desc_from_class is deprecated and will be removed in the next version"
333
+ self.class.class_named_datastreams_desc
295
334
  end
296
- return dsids
297
- end
298
-
299
- # ** EXPERIMENTAL **
300
- #
301
- # Returns the hash that stores arguments passed to has_datastream calls within an
302
- # ActiveFedora::Base child class.
303
- #
304
- # has_datastream :name=>"audio_file", :prefix=>"AUDIO", :type=>ActiveFedora::Datastream, :mimeType=>"audio/x-wav"
305
- # has_datastream :name=>"external_images", :prefix=>"EXTIMG", :type=>ActiveFedora::Datastream,:mimeType=>"image/jpeg", :controlGroup=>'E'
306
- #
307
- # The above examples result in the following hash
308
- # {"audio_file"=>{:prefix=>"AUDIO",:type=>ActiveFedora::Datastream, :mimeType=>"audio/x-wav", :controlGroup=>'M'},
309
- # "external_images=>{:prefix=>"EXTIMG", :type=>ActiveFedora::Datastream,:mimeType=>"image/jpeg", :controlGroup=>'E'}}
310
- #
311
- # This hash is later used when adding a named datastream such as an "audio_file" as defined above.
312
- def named_datastreams_desc
313
- @named_datastreams_desc ||= self.class.class_named_datastreams_desc
314
- end
315
-
316
- # ** EXPERIMENTAL **
317
- #
318
- # Get class variable hash that stores has_datastream arguments.
319
- # It is used to initialize the value returned by public named_datastreams_desc method
320
- # Deprecated
321
- def named_datastreams_desc_from_class
322
- logger.warn "named_datastreams_desc_from_class is deprecated and will be removed in the next version"
323
- self.class.class_named_datastreams_desc
324
- end
325
335
 
336
+ end
326
337
  end