Class: ActiveFedora::Associations::OrdersAssociation
Instance Attribute Summary
#proxy
Attributes inherited from Association
#inversed, #owner, #reflection, #target
Instance Method Summary
collapse
#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
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
58
59
|
# File 'lib/active_fedora/associations/orders_association.rb', line 54
def append_target(record, _skip_callbacks = false)
unless unordered_association.target.include?(record)
unordered_association.concat(record)
end
target.append_target(record, proxy_in: owner)
end
|
#delete_record(record) ⇒ Object
100
101
102
|
# File 'lib/active_fedora/associations/orders_association.rb', line 100
def delete_record(record)
target.delete_node(record)
end
|
#delete_records(records, _method = nil) ⇒ Object
Delete multiple list nodes.
92
93
94
95
96
|
# File 'lib/active_fedora/associations/orders_association.rb', line 92
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
104
105
106
107
108
109
110
111
112
113
114
|
# File 'lib/active_fedora/associations/orders_association.rb', line 104
def insert_record(record, _force = true, _validate = true)
record.save_target
list_container.save
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
64
65
66
67
68
69
|
# File 'lib/active_fedora/associations/orders_association.rb', line 64
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
74
75
76
77
78
79
80
|
# File 'lib/active_fedora/associations/orders_association.rb', line 74
def insert_target_id_at(loc, id)
raise ArgumentError, "ID can not be nil" if id.nil?
unless unordered_association.ids_reader.include?(id)
raise ArgumentError, "#{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
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
116
117
118
|
# File 'lib/active_fedora/associations/orders_association.rb', line 116
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
|