Module: ActiveFedora::Attributes
- Extended by:
- ActiveSupport::Autoload, ActiveSupport::Concern, Deprecation
- 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
15 16 17 18 19 |
# File 'lib/active_fedora/attributes.rb', line 15 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
79 80 81 82 83 84 85 86 |
# File 'lib/active_fedora/attributes.rb', line 79 def get_values_from_datastream(dsid,field_key,default=[]) Deprecation.warn(Attributes, 'get_values_from_datastream is deprecated. Consider using Datastream#get_values instead.', caller) 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
66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/active_fedora/attributes.rb', line 66 def update_datastream_attributes(params={}, opts={}) Deprecation.warn(Attributes, 'update_datastream_attributes is deprecated. Consider using delegate_to instead.', caller) 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"])
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/active_fedora/attributes.rb', line 39 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 |