Class: ActiveFedora::OmDatastream
- Inherits:
-
File
- Object
- File
- ActiveFedora::OmDatastream
- Includes:
- Datastreams::NokogiriDatastreams, OM::XML::Document, OM::XML::TerminologyBasedSolrizer
- Defined in:
- lib/active_fedora/om_datastream.rb
Direct Known Subclasses
Instance Method Summary collapse
- #default_mime_type ⇒ Object
- #find_by_terms(*termpointer) ⇒ Object
- #get_values(field_key, _default = []) ⇒ Object
-
#metadata? ⇒ Boolean
Indicates that this datastream has metadata content.
- #om_update_values ⇒ Object
-
#to_solr(solr_doc = {}, opts = {}) ⇒ Object
Return a hash suitable for indexing in solr.
-
#update_indexed_attributes(params = {}, _opts = {}) ⇒ Object
Update field values within the current datastream using #update_values, which is a wrapper for OM::TermValueOperators#update_values Ignores any fields from params that this datastream’s Terminology doesn’t recognize.
-
#update_values(params = {}) ⇒ Object
Update values in the datastream’s xml This wraps OM::TermValueOperators#update_values so that returns an error if we have loaded from solr since datastreams loaded that way should be read-only.
Methods included from Datastreams::NokogiriDatastreams
#autocreate?, #content, #content=, #content_changed?, #ng_xml, #ng_xml=, #ng_xml_changed?, #ng_xml_doesnt_change!, #ng_xml_will_change!, #refresh_attributes, #remote_content, #to_xml, #xml_loaded
Instance Method Details
#default_mime_type ⇒ Object
19 20 21 |
# File 'lib/active_fedora/om_datastream.rb', line 19 def default_mime_type 'text/xml' end |
#find_by_terms(*termpointer) ⇒ Object
87 88 89 |
# File 'lib/active_fedora/om_datastream.rb', line 87 def find_by_terms(*termpointer) super end |
#get_values(field_key, _default = []) ⇒ Object
83 84 85 |
# File 'lib/active_fedora/om_datastream.rb', line 83 def get_values(field_key, _default = []) term_values(*field_key) end |
#metadata? ⇒ Boolean
Indicates that this datastream has metadata content.
25 26 27 |
# File 'lib/active_fedora/om_datastream.rb', line 25 def true end |
#om_update_values ⇒ Object
17 |
# File 'lib/active_fedora/om_datastream.rb', line 17 alias om_update_values update_values |
#to_solr(solr_doc = {}, opts = {}) ⇒ Object
Return a hash suitable for indexing in solr. Every field name is prefixed with the value returned by the prefix
method.
31 32 33 34 |
# File 'lib/active_fedora/om_datastream.rb', line 31 def to_solr(solr_doc = {}, opts = {}) prefix = self.prefix(opts[:name]) solr_doc.merge super({}).each_with_object({}) { |(key, value), new| new[[prefix, key].join] = value } end |
#update_indexed_attributes(params = {}, _opts = {}) ⇒ Object
Update field values within the current datastream using #update_values, which is a wrapper for OM::TermValueOperators#update_values Ignores any fields from params that this datastream’s Terminology doesn’t recognize
Example:
@mods_ds.update_indexed_attributes( {[{":person"=>"0"}, "role"]=>{"0"=>"role1", "1"=>"role2", "2"=>"role3"} })
=> {"person_0_role"=>{"0"=>"role1", "1"=>"role2", "2"=>"role3"}}
@mods_ds.to_xml # (the following is an approximation)
<mods>
<mods:name type="person">
<mods:role>
<mods:roleTerm>role1</mods:roleTerm>
</mods:role>
<mods:role>
<mods:roleTerm>role2</mods:roleTerm>
</mods:role>
<mods:role>
<mods:roleTerm>role3</mods:roleTerm>
</mods:role>
</mods:name>
</mods>
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/active_fedora/om_datastream.rb', line 61 def update_indexed_attributes(params = {}, _opts = {}) if self.class.terminology.nil? raise "No terminology is set for this OmDatastream class. Cannot perform update_indexed_attributes" end # remove any fields from params that this datastream doesn't recognize # make sure to make a copy of params so not to modify hash that might be passed to other methods current_params = params.clone current_params.delete_if do |term_pointer, new_values| if term_pointer.is_a?(String) ActiveFedora::Base.logger.warn "WARNING: #{self.class.name} ignoring {#{term_pointer.inspect} => #{new_values.inspect}} because #{term_pointer.inspect} is a String (only valid OM Term Pointers will be used). Make sure your html has the correct field_selector tags in it." if ActiveFedora::Base.logger true else !self.class.terminology.has_term?(*OM.destringify(term_pointer)) end end result = {} result = update_values(current_params) unless current_params.empty? result end |
#update_values(params = {}) ⇒ Object
Update values in the datastream’s xml This wraps OM::TermValueOperators#update_values so that returns an error if we have loaded from solr since datastreams loaded that way should be read-only
97 98 99 100 101 102 |
# File 'lib/active_fedora/om_datastream.rb', line 97 def update_values(params = {}) raise "can't modify frozen #{self.class}" if frozen? ng_xml_will_change! result = om_update_values(params) result end |