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
  aggregation.to_a == other
end

#aggregationObject



43
44
45
# File 'lib/active_fedora/aggregation/association.rb', line 43

def aggregation
  @aggregation ||= Aggregator.find_or_initialize(klass.uri_to_id(uri))
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|
    aggregation << created
  end
  save #causes the (head/tail) pointers on the aggregation to be persisted
end

#firstObject



47
48
49
# File 'lib/active_fedora/aggregation/association.rb', line 47

def first
  aggregation.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
  aggregation.save
end

#target=(vals) ⇒ Object



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

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

#target_idsObject



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

def target_ids
  aggregation.target_ids
end

#target_ids=(vals) ⇒ Object



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

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

#uriObject



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

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