class ActiveFedora::Orders::Association

Public Class Methods

new(*args) click to toggle source
Calls superclass method
# File lib/active_fedora/orders/association.rb, line 4
def initialize(*args)
  super
  @target = find_target
end

Public Instance Methods

append_target(record, skip_callbacks=false, &block) click to toggle source

Append a target node to the end of the order. @param [ActiveFedora::Base] record Record to append

# File lib/active_fedora/orders/association.rb, line 52
def append_target(record, skip_callbacks=false, &block)
  unless unordered_association.target.include?(record)
    unordered_association.concat(record)
  end
  target.append_target(record, proxy_in: owner)
end
delete_at(loc) click to toggle source

Delete whatever node is at a specific position @param [Integer] loc Position to delete

# File lib/active_fedora/orders/association.rb, line 82
def delete_at(loc)
  target.delete_at(loc)
end
delete_record(record) click to toggle source

Delete a list node @param [ActiveFedora::Orders::ListNode] record Node to delete.

# File lib/active_fedora/orders/association.rb, line 102
def delete_record(record)
  target.delete_node(record)
end
delete_records(records, _method=nil) click to toggle source

Delete multiple list nodes. @param [Array<ActiveFedora::Orders::ListNode>] records

# File lib/active_fedora/orders/association.rb, line 94
def delete_records(records, _method=nil)
  records.each do |record|
    delete_record(record)
  end
end
delete_target(obj) click to toggle source

Delete all occurences of the specified target @param obj object to delete

# File lib/active_fedora/orders/association.rb, line 88
def delete_target(obj)
  target.delete_target(obj)
end
find_reflection() click to toggle source
# File lib/active_fedora/orders/association.rb, line 31
def find_reflection
  reflection
end
find_target() click to toggle source
# File lib/active_fedora/orders/association.rb, line 42
def find_target
  ordered_proxies
end
insert_record(record, force=true, validate=true) click to toggle source
# File lib/active_fedora/orders/association.rb, line 106
def insert_record(record, force=true, validate=true)
  record.save_target
  list_container.save
  # NOTE: This turns out to be pretty cheap, but should we be doing it
  # elsewhere?
  unless list_container.changed?
    owner.head = [list_container.head_id.first]
    owner.tail = [list_container.tail_id.first]
    owner.save
  end
end
insert_target_at(loc, record) click to toggle source

Insert a target node in a specific position @param [Integer] loc Position to insert record. @param [ActiveFedora::Base] record Record to insert

# File lib/active_fedora/orders/association.rb, line 62
def insert_target_at(loc, record)
  unless unordered_association.target.include?(record)
    unordered_association.concat(record)
  end
  target.insert_at(loc, record, proxy_in: owner)
end
insert_target_id_at(loc, id) click to toggle source

Insert a target ID in a specific position @param [Integer] loc Position to insert record ID @param [String] id ID of record to insert.

# File lib/active_fedora/orders/association.rb, line 72
def insert_target_id_at(loc, id)
  raise ArgumentError.new "ID can not be nil" if id.nil?
  unless unordered_association.ids_reader.include?(id)
    raise ArgumentError.new "#{id} is not a part of #{unordered_association.reflection.name}"
  end
  target.insert_proxy_for_at(loc, ActiveFedora::Base.id_to_uri(id), proxy_in: owner)
end
inspect() click to toggle source
# File lib/active_fedora/orders/association.rb, line 9
def inspect
  "#<ActiveFedora::Orders::Association:#{object_id}>"
end
load_target() click to toggle source
# File lib/active_fedora/orders/association.rb, line 46
def load_target
  @target = find_target
end
reader(*args) click to toggle source
Calls superclass method
# File lib/active_fedora/orders/association.rb, line 13
def reader(*args)
  @proxy ||= ActiveFedora::Orders::CollectionProxy.new(self)
  @null_proxy ||= ActiveFedora::Orders::CollectionProxy.new(self)
  super
end
replace(new_ordered_list) click to toggle source
# File lib/active_fedora/orders/association.rb, line 35
def replace(new_ordered_list)
  raise unless new_ordered_list.kind_of? ActiveFedora::Orders::OrderedList
  list_container.ordered_self = new_ordered_list
  @target = find_target
end
scope(*args) click to toggle source
# File lib/active_fedora/orders/association.rb, line 118
def scope(*args)
  @scope ||= ActiveFedora::Relation.new(klass)
end
target_reader() click to toggle source
# File lib/active_fedora/orders/association.rb, line 27
def target_reader
  @target_proxy ||= TargetProxy.new(self)
end
target_writer(nodes) click to toggle source

Meant to override all nodes with the given nodes. @param [Array<ActiveFedora::Base>] nodes Nodes to set as ordered members

# File lib/active_fedora/orders/association.rb, line 21
def target_writer(nodes)
  target_reader.clear
  target_reader.concat(nodes)
  target_reader
end

Private Instance Methods

association_scope() click to toggle source
# File lib/active_fedora/orders/association.rb, line 135
def association_scope
  nil
end
create_list_node(record) click to toggle source
# File lib/active_fedora/orders/association.rb, line 128
def create_list_node(record)
  node = ListNode.new(RDF::URI.new("#{list_container.uri}##{::RDF::Node.new.id}"), list_container.resource)
  node.proxyIn = owner
  node.proxyFor = record
  node
end
list_container() click to toggle source
# File lib/active_fedora/orders/association.rb, line 139
def list_container
  list_container_association.reader
end
list_container_association() click to toggle source
# File lib/active_fedora/orders/association.rb, line 143
def list_container_association
  owner.association(options[:through])
end
ordered_proxies() click to toggle source
# File lib/active_fedora/orders/association.rb, line 124
def ordered_proxies
  list_container.ordered_self
end
unordered_association() click to toggle source
# File lib/active_fedora/orders/association.rb, line 147
def unordered_association
  owner.association(unordered_reflection_name)
end
unordered_reflection_name() click to toggle source
# File lib/active_fedora/orders/association.rb, line 151
def unordered_reflection_name
  reflection.unordered_reflection.name
end