Module: Rubydora::ModelsMixin

Included in:
DigitalObject
Defined in:
lib/rubydora/models_mixin.rb

Overview

Provide access to registered content models FIXME: Ruby 1.9 provides instance_exec, which should make it possible to subsume this into Rubydora::RelationshipsMixin

Instance Method Summary collapse

Instance Method Details

#models(args = {}) ⇒ ArrayWithCallback<Rubydora::DigitalObject>

Provides an accessor to the object content models

Parameters:

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

Options Hash (args):

  • :values (Array)

    if nil, will query the resource index for related objects

Returns:



12
13
14
15
# File 'lib/rubydora/models_mixin.rb', line 12

def models args = {}
  @models = nil if args.delete(:refetch)
  @models ||= relationship('info:fedora/fedora-system:def/model#hasModel', :values => args[:values] || profile['objModels'] || [])
end

#models=(arr) ⇒ Object Also known as: model=

provides a setter that behaves as does #models



18
19
20
21
22
23
24
25
# File 'lib/rubydora/models_mixin.rb', line 18

def models= arr
  arr &&= [arr] unless arr.is_a? Array
  old = models.dup || []
  arr = @models = relationship('info:fedora/fedora-system:def/model#hasModel', :values => arr.flatten)
  relationship_changed('info:fedora/fedora-system:def/model#hasModel', {:+ => arr - old, :- => old - arr }, @models)

  @models
end