Class: ActiveFedora::Associations::OrdersAssociation
- Inherits:
-
CollectionAssociation
- Object
- Association
- CollectionAssociation
- ActiveFedora::Associations::OrdersAssociation
- Defined in:
- lib/active_fedora/associations/orders_association.rb
Instance Attribute Summary
Attributes inherited from CollectionAssociation
Attributes inherited from Association
#inversed, #owner, #reflection, #target
Instance Method Summary collapse
-
#append_target(record, _skip_callbacks = false) ⇒ Object
Append a target node to the end of the order.
-
#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) ⇒ OrdersAssociation
constructor
A new instance of OrdersAssociation.
- #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_ids_reader ⇒ Object
- #target_reader ⇒ Object
-
#target_writer(nodes) ⇒ Object
Meant to override all nodes with the given nodes.
Methods inherited from CollectionAssociation
#add_to_target, #any?, #build, #concat, #concat_records, #count, #create, #create!, #delete, #delete_all, #destroy, #destroy_all, #empty?, #find, #first, #ids_reader, #ids_writer, #include?, #last, #load_from_solr, #null_scope?, #reset, #select, #size, #target=, #to_ary, #writer
Methods inherited from Association
#initialize_attributes, #loaded!, #loaded?, #reload, #reset, #reset_scope, #set_inverse_instance, #stale_target?, #target_scope
Constructor Details
#initialize(*args) ⇒ OrdersAssociation
Returns a new instance of OrdersAssociation.
3 4 5 6 |
# File 'lib/active_fedora/associations/orders_association.rb', line 3 def initialize(*args) super @target = find_target end |
Instance Method Details
#append_target(record, _skip_callbacks = false) ⇒ Object
Append a target node to the end of the order.
54 55 56 57 |
# 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) ⇒ Object
Delete a list node
94 95 96 |
# File 'lib/active_fedora/associations/orders_association.rb', line 94 def delete_record(record) target.delete_node(record) end |
#delete_records(records, _method = nil) ⇒ Object
Delete multiple list nodes.
86 87 88 89 90 |
# 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 ⇒ Object
34 35 36 |
# File 'lib/active_fedora/associations/orders_association.rb', line 34 def find_reflection reflection end |
#find_target ⇒ Object
44 45 46 |
# File 'lib/active_fedora/associations/orders_association.rb', line 44 def find_target ordered_proxies end |
#insert_record(record, _force = true, _validate = true) ⇒ Object
98 99 100 101 102 103 104 105 106 107 |
# 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) ⇒ Object
Insert a target node in a specific position
62 63 64 65 |
# 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) ⇒ Object
Insert a target ID in a specific position
70 71 72 73 74 |
# 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 ⇒ Object
8 9 10 |
# File 'lib/active_fedora/associations/orders_association.rb', line 8 def inspect "#<ActiveFedora::Associations::OrdersAssociation:#{object_id}>" end |
#load_target ⇒ Object
48 49 50 |
# File 'lib/active_fedora/associations/orders_association.rb', line 48 def load_target @target = find_target end |
#reader(*args) ⇒ Object
12 13 14 15 16 |
# 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) ⇒ Object
38 39 40 41 42 |
# 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) ⇒ Object
109 110 111 |
# File 'lib/active_fedora/associations/orders_association.rb', line 109 def scope(*_args) @scope ||= ActiveFedora::Relation.new(klass) end |
#target_ids_reader ⇒ Object
30 31 32 |
# File 'lib/active_fedora/associations/orders_association.rb', line 30 def target_ids_reader target_reader.ids end |
#target_reader ⇒ Object
26 27 28 |
# File 'lib/active_fedora/associations/orders_association.rb', line 26 def target_reader @target_proxy ||= ActiveFedora::Orders::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/associations/orders_association.rb', line 20 def target_writer(nodes) target_reader.clear target_reader.concat(nodes) target_reader end |