module AdminIt::ActiveRecordData::CollectionContext

Public Instance Methods

entities=(value) click to toggle source
Calls superclass method
# File lib/admin_it/data/active_record/collection_context.rb, line 5
def entities=(value)
  super(value)
  @count = @entities.nil? ? 0 : @entities.count
end

Protected Instance Methods

load_entities() click to toggle source
# File lib/admin_it/data/active_record/collection_context.rb, line 12
def load_entities
  collection =
    if AdminIt::Env.pundit?
      controller.policy_scope(entity_class)
    else
      entity_class.all
    end
  if child?
    collection = collection.where(parent.resource.name => parent.entity)
  end
  sort = {}
  sorting.each do |_sort|
    name, order = _sort.split(':')
    sort[name.to_sym] = order.to_sym
  end
  unless collection.nil? || sort.empty?
    collection = collection.order(sort)
  end
  collection
end