class ActiveFedora::Associations::OrdersAssociation

Public Class Methods

new(*args) click to toggle source
# File lib/active_fedora/associations/orders_association.rb, line 3
def initialize(*args)
  super
  @target = find_target
end

Public Instance Methods

append_target(record, _skip_callbacks = false) 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/associations/orders_association.rb, line 54
def append_target(record, _skip_callbacks = false)
  unordered_association.concat(record) unless unordered_association.target.include?(record)
  target.append_target(record, proxy_in: owner)
end
delete_record(record) click to toggle source

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

# File lib/active_fedora/associations/orders_association.rb, line 94
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/associations/orders_association.rb, line 86
def delete_records(records, _method = nil)
  records.each do |record|
    delete_record(record)
  end
end
find_reflection() click to toggle source
# File lib/active_fedora/associations/orders_association.rb, line 34
def find_reflection
  reflection
end
find_target() click to toggle source
# File lib/active_fedora/associations/orders_association.rb, line 44
def find_target
  ordered_proxies
end
insert_record(record, _force = true, _validate = true) click to toggle source
# File lib/active_fedora/associations/orders_association.rb, line 98
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?
  return if list_container.changed?
  owner.head = [list_container.head_id.first]
  owner.tail = [list_container.tail_id.first]
  owner.save
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/associations/orders_association.rb, line 62
def insert_target_at(loc, record)
  unordered_association.concat(record) unless unordered_association.target.include?(record)
  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/associations/orders_association.rb, line 70
def insert_target_id_at(loc, id)
  raise ArgumentError, "ID can not be nil" if id.nil?
  raise ArgumentError, "#{id} is not a part of #{unordered_association.reflection.name}" unless unordered_association.ids_reader.include?(id)
  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/associations/orders_association.rb, line 8
def inspect
  "#<ActiveFedora::Associations::OrdersAssociation:#{object_id}>"
end
load_target() click to toggle source
# File lib/active_fedora/associations/orders_association.rb, line 48
def load_target
  @target = find_target
end
reader(*args) click to toggle source
Calls superclass method
# File lib/active_fedora/associations/orders_association.rb, line 12
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/associations/orders_association.rb, line 38
def replace(new_ordered_list)
  raise unless new_ordered_list.is_a? ActiveFedora::Orders::OrderedList
  list_container.ordered_self = new_ordered_list
  @target = find_target
end
scope(*_args) click to toggle source
# File lib/active_fedora/associations/orders_association.rb, line 109
def scope(*_args)
  @scope ||= ActiveFedora::Relation.new(klass)
end
target_ids_reader() click to toggle source
# File lib/active_fedora/associations/orders_association.rb, line 30
def target_ids_reader
  target_reader.ids
end
target_reader() click to toggle source
# File lib/active_fedora/associations/orders_association.rb, line 26
def target_reader
  @target_proxy ||= ActiveFedora::Orders::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/associations/orders_association.rb, line 20
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/associations/orders_association.rb, line 126
def association_scope
  nil
end
create_list_node(record) click to toggle source
# File lib/active_fedora/associations/orders_association.rb, line 119
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/associations/orders_association.rb, line 130
def list_container
  list_container_association.reader
end
list_container_association() click to toggle source
# File lib/active_fedora/associations/orders_association.rb, line 134
def list_container_association
  owner.association(options[:through])
end
ordered_proxies() click to toggle source
# File lib/active_fedora/associations/orders_association.rb, line 115
def ordered_proxies
  list_container.ordered_self
end
unordered_association() click to toggle source
# File lib/active_fedora/associations/orders_association.rb, line 138
def unordered_association
  owner.association(unordered_reflection_name)
end
unordered_reflection_name() click to toggle source
# File lib/active_fedora/associations/orders_association.rb, line 142
def unordered_reflection_name
  reflection.unordered_reflection.name
end