Class: ActiveFedora::Orders::TargetProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/active_fedora/orders/target_proxy.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(association) ⇒ TargetProxy

Returns a new instance of TargetProxy.



6
7
8
# File 'lib/active_fedora/orders/target_proxy.rb', line 6

def initialize(association)
  @association = association
end

Instance Attribute Details

#associationObject (readonly)

Returns the value of attribute association.



4
5
6
# File 'lib/active_fedora/orders/target_proxy.rb', line 4

def association
  @association
end

Instance Method Details

#<<(obj) ⇒ Object



10
11
12
13
# File 'lib/active_fedora/orders/target_proxy.rb', line 10

def <<(obj)
  association.append_target(obj)
  self
end

#==(other) ⇒ Object



54
55
56
57
58
59
60
61
# File 'lib/active_fedora/orders/target_proxy.rb', line 54

def ==(other)
  case other
  when TargetProxy
    super
  when Array
    to_a == other
  end
end

#clearObject



45
46
47
# File 'lib/active_fedora/orders/target_proxy.rb', line 45

def clear
  association.delete_at(0) while to_ary.present?
end

#concat(objs) ⇒ Object



15
16
17
18
19
20
# File 'lib/active_fedora/orders/target_proxy.rb', line 15

def concat(objs)
  objs.each do |obj|
    self.<<(obj)
  end
  self
end

#delete(obj) ⇒ Object

Deletes all items from self that are equal to obj.

Parameters:

  • obj

    the object to remove from the list

Returns:

  • the last deleted item, or nil if no matching item is found



41
42
43
# File 'lib/active_fedora/orders/target_proxy.rb', line 41

def delete(obj)
  association.delete_target(obj)
end

#delete_at(loc) ⇒ Object

Deletes the element at the specified index, returning that element, or nil if the index is out of range.



33
34
35
36
# File 'lib/active_fedora/orders/target_proxy.rb', line 33

def delete_at(loc)
  result = association.delete_at(loc)
  result.target if result
end

#idsObject



27
28
29
# File 'lib/active_fedora/orders/target_proxy.rb', line 27

def ids
  association.reader.map(&:target_id)
end

#insert_at(loc, record) ⇒ Object



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

def insert_at(loc, record)
  association.insert_target_at(loc, record)
  self
end

#to_aryObject Also known as: to_a



49
50
51
# File 'lib/active_fedora/orders/target_proxy.rb', line 49

def to_ary
  association.reader.map(&:target).dup
end