Class: ActiveFedora::Orders::Association
- Inherits:
-
Associations::CollectionAssociation
- Object
- Associations::CollectionAssociation
- ActiveFedora::Orders::Association
- Defined in:
- lib/active_fedora/orders/association.rb
Instance Method Summary collapse
-
#append_target(record, skip_callbacks = false, &block) ⇒ Object
Append a target node to the end of the order.
-
#delete_at(loc) ⇒ Object
Delete whatever node is at a specific position.
-
#delete_record(record) ⇒ Object
Delete a list node.
-
#delete_records(records, _method = nil) ⇒ Object
Delete multiple list nodes.
- #find_reflection ⇒ Object
- #find_target ⇒ Object
-
#initialize(*args) ⇒ Association
constructor
A new instance of Association.
- #insert_record(record, force = true, validate = true) ⇒ Object
-
#insert_target_at(loc, record) ⇒ Object
Insert a target node in a specific position.
-
#insert_target_id_at(loc, id) ⇒ Object
Insert a target ID in a specific position.
- #inspect ⇒ Object
- #load_target ⇒ Object
- #reader(*args) ⇒ Object
- #replace(new_ordered_list) ⇒ Object
- #scope(*args) ⇒ Object
- #target_reader ⇒ Object
-
#target_writer(nodes) ⇒ Object
Meant to override all nodes with the given nodes.
Constructor Details
#initialize(*args) ⇒ Association
Returns a new instance of Association.
4 5 6 7 |
# File 'lib/active_fedora/orders/association.rb', line 4 def initialize(*args) super @target = find_target end |
Instance Method Details
#append_target(record, skip_callbacks = false, &block) ⇒ Object
Append a target node to the end of the order.
51 52 53 54 55 56 |
# File 'lib/active_fedora/orders/association.rb', line 51 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) ⇒ Object
Delete whatever node is at a specific position
81 82 83 |
# File 'lib/active_fedora/orders/association.rb', line 81 def delete_at(loc) target.delete_at(loc) end |
#delete_record(record) ⇒ Object
Delete a list node
95 96 97 |
# File 'lib/active_fedora/orders/association.rb', line 95 def delete_record(record) target.delete_node(record) end |
#delete_records(records, _method = nil) ⇒ Object
Delete multiple list nodes.
87 88 89 90 91 |
# File 'lib/active_fedora/orders/association.rb', line 87 def delete_records(records, _method=nil) records.each do |record| delete_record(record) end end |
#find_reflection ⇒ Object
30 31 32 |
# File 'lib/active_fedora/orders/association.rb', line 30 def find_reflection reflection end |
#find_target ⇒ Object
41 42 43 |
# File 'lib/active_fedora/orders/association.rb', line 41 def find_target ordered_proxies end |
#insert_record(record, force = true, validate = true) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/active_fedora/orders/association.rb', line 99 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) ⇒ Object
Insert a target node in a specific position
61 62 63 64 65 66 |
# File 'lib/active_fedora/orders/association.rb', line 61 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) ⇒ Object
Insert a target ID in a specific position
71 72 73 74 75 76 77 |
# File 'lib/active_fedora/orders/association.rb', line 71 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 ⇒ Object
9 10 11 |
# File 'lib/active_fedora/orders/association.rb', line 9 def inspect "#<ActiveFedora::Orders::Association:#{object_id}>" end |
#load_target ⇒ Object
45 46 47 |
# File 'lib/active_fedora/orders/association.rb', line 45 def load_target @target = find_target end |
#reader(*args) ⇒ Object
13 14 15 16 |
# File 'lib/active_fedora/orders/association.rb', line 13 def reader(*args) @proxy ||= ActiveFedora::Orders::CollectionProxy.new(self) super end |
#replace(new_ordered_list) ⇒ Object
34 35 36 37 38 |
# File 'lib/active_fedora/orders/association.rb', line 34 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) ⇒ Object
111 112 113 |
# File 'lib/active_fedora/orders/association.rb', line 111 def scope(*args) @scope ||= ActiveFedora::Relation.new(klass) end |
#target_reader ⇒ Object
26 27 28 |
# File 'lib/active_fedora/orders/association.rb', line 26 def target_reader @target_proxy ||= TargetProxy.new(self) end |
#target_writer(nodes) ⇒ Object
Meant to override all nodes with the given nodes.
20 21 22 23 24 |
# File 'lib/active_fedora/orders/association.rb', line 20 def target_writer(nodes) target_reader.clear target_reader.concat(nodes) target_reader end |