Class: ContributorsAssociation

Inherits:
Object
  • Object
show all
Defined in:
lib/contributors_association.rb

Overview

< ActiveFedora::Associations::Association TODO when AF 7 is out

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(owner, reflection) ⇒ ContributorsAssociation

Returns a new instance of ContributorsAssociation.



8
9
10
11
# File 'lib/contributors_association.rb', line 8

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

Instance Attribute Details

#ownerObject (readonly)

Returns the value of attribute owner.



6
7
8
# File 'lib/contributors_association.rb', line 6

def owner
  @owner
end

Instance Method Details

#<<(*records) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/contributors_association.rb', line 18

def <<(*records)
  result = true
  load_target unless loaded?
  records.flatten.each do |record|
    raise_on_type_mismatch(record)
    add_record_to_target_with_callbacks(record) do |r|
      result &&= insert_record(record)
    end
  end
  # return self so you can do method chaining (e.g. assoc << record1 << record2 )
  result && self
end

#build(args = {}) ⇒ Object



38
39
40
41
# File 'lib/contributors_association.rb', line 38

def build args={}
  p = klass.create!(args)
  insert_record(p)
end

#delete(record) ⇒ Object



44
45
46
47
# File 'lib/contributors_association.rb', line 44

def delete record
  owner.send(field_name).delete(record.as_rdf_object)
  load_target
end

#loaded?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/contributors_association.rb', line 14

def loaded?
  @loaded
end

#to_aryObject Also known as: to_a



31
32
33
34
# File 'lib/contributors_association.rb', line 31

def to_ary
  load_target unless loaded?
  @target
end