Module: ActiveFedora::Attributes
- Extended by:
- ActiveSupport::Autoload, ActiveSupport::Concern
- Defined in:
- lib/active_fedora/attributes.rb,
lib/active_fedora/attributes/serializers.rb
Defined Under Namespace
Modules: Serializers
Instance Method Summary collapse
- #attributes=(properties) ⇒ Object
- #get_values_from_datastream(dsid, field_key, default = []) ⇒ Object
-
#update_datastream_attributes(params = {}, opts = {}) ⇒ Object
Updates the attributes for each datastream named in the params Hash.
-
#update_indexed_attributes(params = {}, opts = {}) ⇒ Object
A convenience method for updating indexed attributes.
Instance Method Details
#attributes=(properties) ⇒ Object
11 12 13 14 15 |
# File 'lib/active_fedora/attributes.rb', line 11 def attributes=(properties) properties.each do |k, v| respond_to?(:"#{k}=") ? send(:"#{k}=", v) : raise(UnknownAttributeError, "unknown attribute: #{k}") end end |
#get_values_from_datastream(dsid, field_key, default = []) ⇒ Object
74 75 76 77 78 79 80 |
# File 'lib/active_fedora/attributes.rb', line 74 def get_values_from_datastream(dsid,field_key,default=[]) if datastreams.include?(dsid) return datastreams[dsid].get_values(field_key,default) else return nil end end |
#update_datastream_attributes(params = {}, opts = {}) ⇒ Object
Updates the attributes for each datastream named in the params Hash
62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/active_fedora/attributes.rb', line 62 def update_datastream_attributes(params={}, opts={}) result = params.dup params.each_pair do |dsid, ds_params| if datastreams.include?(dsid) result[dsid] = datastreams[dsid].update_indexed_attributes(ds_params) else result.delete(dsid) end end return result end |
#update_indexed_attributes(params = {}, opts = {}) ⇒ Object
A convenience method for updating indexed attributes. The passed in hash must look like this :
{{:name=>{"0"=>"a","1"=>"b"}}
This will result in any datastream field of name :name having the value [a,b]
An index of -1 will insert a new value. any existing value at the relevant index will be overwritten.
As in update_attributes, this overwrites all available fields by default.
If you want to specify which datastream(s) to update, use the :datastreams argument like so:
m.update_attributes({"fubar"=>{"-1"=>"mork", "0"=>"york", "1"=>"mangle"}}, :datastreams=>"my_ds")
or
m.update_attributes({"fubar"=>{"-1"=>"mork", "0"=>"york", "1"=>"mangle"}}, :datastreams=>["my_ds", "my_other_ds"])
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/active_fedora/attributes.rb', line 35 def update_indexed_attributes(params={}, opts={}) if ds = opts[:datastreams] ds_array = [] ds = [ds] unless ds.respond_to? :each ds.each do |dsname| ds_array << datastreams[dsname] end else ds_array = end result = {} ds_array.each do |d| result[d.dsid] = d.update_indexed_attributes(params,opts) end return result end |