class ActiveFedora::Associations::FilterAssociation
Public Instance Methods
concat(records)
click to toggle source
@param [Array] records a list of records to append to the current association @raise [ArgumentError] if one of the records doesn’t match the prescribed condition
# File lib/active_fedora/associations/filter_association.rb, line 17 def concat(records) records.flatten.each { |r| validate_assertion!(r) } extending_from.concat(records) end
count_records()
click to toggle source
# File lib/active_fedora/associations/filter_association.rb, line 27 def count_records ids_reader.length end
ids_reader()
click to toggle source
Calls superclass method
# File lib/active_fedora/associations/filter_association.rb, line 22 def ids_reader load_target super end
writer(records)
click to toggle source
@param [Array] records a list of records to replace the current association with @raise [ArgumentError] if one of the records doesn’t match the prescribed condition
# File lib/active_fedora/associations/filter_association.rb, line 5 def writer(records) records.each { |r| validate_assertion!(r) } existing_matching_records.each do |r| extending_from.delete(r) end extending_from.concat(records) end
Private Instance Methods
association_scope()
click to toggle source
We can’t create an association scope on here until we can figure a way to index/query the condition in Solr
# File lib/active_fedora/associations/filter_association.rb, line 49 def association_scope nil end
existing_matching_records()
click to toggle source
# File lib/active_fedora/associations/filter_association.rb, line 53 def existing_matching_records extending_from.reader.to_a.select do |r| validate_assertion(r) end end
extending_from()
click to toggle source
# File lib/active_fedora/associations/filter_association.rb, line 59 def extending_from owner.association(options.fetch(:extending_from)) end
find_target()
click to toggle source
# File lib/active_fedora/associations/filter_association.rb, line 43 def find_target existing_matching_records end
find_target?()
click to toggle source
# File lib/active_fedora/associations/filter_association.rb, line 39 def find_target? true end
target()
click to toggle source
target should never be cached as part of this objects state, because extending_from.target could change and we want to reflect those changes
# File lib/active_fedora/associations/filter_association.rb, line 35 def target find_target end
validate_assertion(record)
click to toggle source
# File lib/active_fedora/associations/filter_association.rb, line 63 def validate_assertion(record) record.send(options.fetch(:condition)) end
validate_assertion!(record)
click to toggle source
# File lib/active_fedora/associations/filter_association.rb, line 67 def validate_assertion!(record) raise ArgumentError, "#{record.class} with ID: #{record.id} was expected to #{options.fetch(:condition)}, but it was false" unless validate_assertion(record) end