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



50
51
52
53
54
55
56
57
# File 'lib/active_fedora/orders/target_proxy.rb', line 50

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

#clearObject



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

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



37
38
39
# File 'lib/active_fedora/orders/target_proxy.rb', line 37

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.



29
30
31
32
# File 'lib/active_fedora/orders/target_proxy.rb', line 29

def delete_at(loc)
  result = association.delete_at(loc)
  result.target if result
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



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

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