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: ClassMethods, Serializers

Instance Method Summary collapse

Instance Method Details

#[](key) ⇒ Object



32
33
34
# File 'lib/active_fedora/attributes.rb', line 32

def [](key)
  array_reader(key)
end

#[]=(key, value) ⇒ Object



36
37
38
# File 'lib/active_fedora/attributes.rb', line 36

def []=(key, value)
  array_setter(key, value)
end

#attributes=(properties) ⇒ Object



20
21
22
23
24
# File 'lib/active_fedora/attributes.rb', line 20

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



238
239
240
241
242
243
244
245
# File 'lib/active_fedora/attributes.rb', line 238

def get_values_from_datastream(dsid,field_key,default=[])
  Deprecation.warn(Attributes, 'get_values_from_datastream is deprecated and will be removed in ActiveFedora 7.0.0. Consider using Datastream#get_values instead.', caller)
  if datastreams.include?(dsid)
    return datastreams[dsid].get_values(field_key,default)
  else
    return nil
  end
end

#inspectObject

Calling inspect may trigger a bunch of loads, but it’s mainly for debugging, so no worries.



27
28
29
30
# File 'lib/active_fedora/attributes.rb', line 27

def inspect
  values = self.class.defined_attributes.keys.map {|r| "#{r}:#{send(r).inspect}"}
  "#<#{self.class} pid:\"#{pretty_pid}\", #{values.join(', ')}>"
end

#update_datastream_attributes(params = {}, opts = {}) ⇒ Object

Updates the attributes for each datastream named in the params Hash

Examples:

Update the descMetadata and properties datastreams with new values

article = HydrangeaArticle.new
ds_values_hash = {
  "descMetadata"=>{ [{:person=>0}, :role]=>{"0"=>"role1", "1"=>"role2", "2"=>"role3"} },
  "properties"=>{ "notes"=>"foo" }
}
article.update_datastream_attributes( ds_values_hash )

Parameters:

  • params (Hash) (defaults to: {})

    A Hash whose keys correspond to datastream ids and whose values are appropriate Hashes to submit to update_indexed_attributes on that datastream

  • opts (Hash) (defaults to: {})

    (currently ignored.)



225
226
227
228
229
230
231
232
233
234
235
236
# File 'lib/active_fedora/attributes.rb', line 225

def update_datastream_attributes(params={}, opts={})
  Deprecation.warn(Attributes, 'update_datastream_attributes is deprecated and will be removed in ActiveFedora 7.0.0. 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"])


197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
# File 'lib/active_fedora/attributes.rb', line 197

def update_indexed_attributes(params={}, opts={})
  Deprecation.warn(Attributes, 'update_indexed_attributes is deprecated and will be removed in ActiveFedora 7.0.0. Consider using dsid.update_indexed_attributes() instead.', caller)
  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