Class: ActiveFedora::OmDatastream
- Includes:
- Datastreams::NokogiriDatastreams, OM::XML::Document, OM::XML::TerminologyBasedSolrizer
- Defined in:
- lib/active_fedora/om_datastream.rb
Direct Known Subclasses
Constant Summary
Constants included from AttributeMethods
AttributeMethods::AttrNames, AttributeMethods::BLACKLISTED_CLASS_METHODS
Constants included from Callbacks
Instance Method Summary collapse
- #default_mime_type ⇒ Object
- #find_by_terms(*termpointer) ⇒ Object
- #get_values(field_key, _default = []) ⇒ Object
-
#has_solr_name?(name, solr_doc = {}) ⇒ Boolean
** Experimental **.
-
#is_hierarchical_term_pointer?(*term_pointer) ⇒ Boolean
** Experimental ** ====Example: [:image, :title_set=>1, :title] return true [:image, :title_set, :title] return false.
-
#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
Methods inherited from File
#attribute_will_change!, #changed?, #check_fixity, #checksum, #content, #content=, #content_changed?, #datastream_will_change!, #described_by, #exists!, #initialize, #inspect, #ldp_connection, #metadata, #metadata_changed?, #new_record?, #refresh, #reload, #remote_content, #save, #serialize!, #uri=
Methods included from Querying
#default_sort_params, extended
Methods included from Scoping
#initialize_internals_callback, #populate_with_current_scope_attributes
Methods included from Identifiable
Methods included from AttributeMethods
#[], #[]=, #attribute_for_inspect, #attribute_names, #attribute_present?, #attributes, #has_attribute?
Methods included from Callbacks
Methods included from Versionable
#create_version, #has_versions?, #model_type, #restore_version, #versions
Methods included from Persistence
#delete, #destroy, #destroy!, #destroyed?, #eradicate, #new_record?, #persisted?, #save, #save!, #update
Methods included from File::Streaming
Methods included from File::Attributes
#create_date, #digest, #dirty_size, #empty?, #has_content?, #mime_type, #original_name, #original_name=, #persisted_size, #size
Methods included from Common
#<=>, #==, #freeze, #frozen?, #ldp_source, #readonly!, #readonly?
Constructor Details
This class inherits a constructor from ActiveFedora::File
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
109 110 111 |
# File 'lib/active_fedora/om_datastream.rb', line 109 def find_by_terms(*termpointer) super end |
#get_values(field_key, _default = []) ⇒ Object
105 106 107 |
# File 'lib/active_fedora/om_datastream.rb', line 105 def get_values(field_key, _default = []) term_values(*field_key) end |
#has_solr_name?(name, solr_doc = {}) ⇒ Boolean
** Experimental **
40 41 42 |
# File 'lib/active_fedora/om_datastream.rb', line 40 def has_solr_name?(name, solr_doc = {}) !solr_doc[name].nil? || !solr_doc[name.to_s].nil? end |
#is_hierarchical_term_pointer?(*term_pointer) ⇒ Boolean
** Experimental **
Example:
[:image, {:title_set=>1}, :title] return true
[:image, :title_set, :title] return false
49 50 51 52 53 54 55 56 |
# File 'lib/active_fedora/om_datastream.rb', line 49 def is_hierarchical_term_pointer?(*term_pointer) if term_pointer.length > 1 term_pointer.each do |pointer| return true if pointer.is_a?(Hash) end end false 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>
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/active_fedora/om_datastream.rb', line 83 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
119 120 121 122 123 124 |
# File 'lib/active_fedora/om_datastream.rb', line 119 def update_values(params = {}) raise "can't modify frozen #{self.class}" if frozen? ng_xml_will_change! result = om_update_values(params) result end |