module ReactiveRecord::ScopedCollection
The base collection class works with relationships method overrides for scoped collections
Public Instance Methods
sync_scopes(related_records, record, filtering = true)
click to toggle source
# File lib/reactive_record/active_record/reactive_record/scoped_collection.rb, line 19 def sync_scopes(related_records, record, filtering = true) filtering = @pre_sync_related_records && filtering && ReactiveRecord::Base.catch_db_requests do related_records = update_collection(related_records) end reload_from_db if !filtering && joins_with?(record) live_scopes.each { |scope| scope.sync_scopes(related_records, record, filtering) } ensure @pre_sync_related_records = nil end
update_collection(related_records)
click to toggle source
# File lib/reactive_record/active_record/reactive_record/scoped_collection.rb, line 31 def update_collection(related_records) if collector? update_collector_scope(related_records) else related_records = filter_records(related_records) update_filter_scope(@pre_sync_related_records, related_records) end end
update_collector_scope(related_records)
click to toggle source
# File lib/reactive_record/active_record/reactive_record/scoped_collection.rb, line 40 def update_collector_scope(related_records) current = Set.new([*@collection]) (related_records - @pre_sync_related_records).each { |r| current << r } (@pre_sync_related_records - related_records).each { |r| current.delete(r) } replace(filter_records(current)) Set.new([*@collection]) end
update_filter_scope(before, after)
click to toggle source
# File lib/reactive_record/active_record/reactive_record/scoped_collection.rb, line 48 def update_filter_scope(before, after) if (collection || !@count.nil?) && before != after if collection (after - before).each { |r| push r } (before - after).each { |r| delete r } else @count += (after - before).count @count -= (before - after).count notify_of_change self # TODO remove self .... and retest end end after end