Module: ActiveFedora::Delegating::ClassMethods

Defined in:
lib/active_fedora/delegating.rb

Instance Method Summary collapse

Instance Method Details

#delegate(field, args = {}) ⇒ Object

Provides a delegate class method to expose methods in metadata streams as member of the base object. Pass the target datastream via the :to argument. If you want to return a unique result, (e.g. string instead of an array) set the :unique argument to true.

class Foo < ActiveFedora::Base
   :name => "descMetadata", :type => MyDatastream 

  delegate :field1, :to=>"descMetadata", :unique=>true
end

foo = Foo.new
foo.field1 = "My Value"
foo.field1                 # => "My Value"
foo.field2                 # => NoMethodError: undefined method `field2' for #<Foo:0x1af30c>


22
23
24
25
# File 'lib/active_fedora/delegating.rb', line 22

def delegate(field, args ={})
  create_delegate_accessor(field, args)
  create_delegate_setter(field, args)
end