Class: ActiveFedora::Aggregation::Association

Inherits:
Object
  • Object
show all
Defined in:
lib/active_fedora/aggregation/association.rb

Instance Method Summary collapse

Constructor Details

#initialize(parent, reflection) ⇒ Association

Returns a new instance of Association.

Parameters:

  • parent (ActiveFedora::Base)
  • reflection (Reflection)


7
8
9
10
# File 'lib/active_fedora/aggregation/association.rb', line 7

def initialize(parent, reflection)
  @parent = parent
  @reflection = reflection
end

Instance Method Details

#==(other) ⇒ Object



16
17
18
# File 'lib/active_fedora/aggregation/association.rb', line 16

def == other
  container.to_a == other
end

#containerObject



43
44
45
46
47
48
49
# File 'lib/active_fedora/aggregation/association.rb', line 43

def container
  @container ||= begin
     ProxyContainer.find_or_initialize(klass.uri_to_id(uri)).tap do |container|
       container.parent = @parent
     end
  end
end

#create(&block) ⇒ Object



20
21
22
23
24
25
# File 'lib/active_fedora/aggregation/association.rb', line 20

def create(&block)
  klass.create(&block).tap do |created|
    container << created
  end
  save #causes the (head/tail) pointers on the aggregation to be persisted
end

#firstObject



51
52
53
# File 'lib/active_fedora/aggregation/association.rb', line 51

def first
  container.first
end

#klassObject



12
13
14
# File 'lib/active_fedora/aggregation/association.rb', line 12

def klass
  @reflection.klass
end

#saveObject



27
28
29
# File 'lib/active_fedora/aggregation/association.rb', line 27

def save
  container.save
end

#target=(vals) ⇒ Object



31
32
33
# File 'lib/active_fedora/aggregation/association.rb', line 31

def target=(vals)
  container.target=(vals)
end

#target_idsObject



39
40
41
# File 'lib/active_fedora/aggregation/association.rb', line 39

def target_ids
  container.target_ids
end

#target_ids=(vals) ⇒ Object



35
36
37
# File 'lib/active_fedora/aggregation/association.rb', line 35

def target_ids=(vals)
  container.target_ids=(vals)
end

#uriObject



55
56
57
# File 'lib/active_fedora/aggregation/association.rb', line 55

def uri
  @parent.uri + '/files'
end