class ActiveRecordEx::NillableFind::NillableArel

Public Class Methods

new(base, ids, parent_scope) click to toggle source
# File lib/active-record-ex/nillable_find.rb, line 4
def initialize(base, ids, parent_scope)
  @base = base
  @ids = ids
  @parent_scope = parent_scope
end

Public Instance Methods

method_missing(method_name, *args, &block) click to toggle source
Calls superclass method
# File lib/active-record-ex/nillable_find.rb, line 10
def method_missing(method_name, *args, &block)
  return super unless  @base.respond_to? method_name

  normals = @base.where(id: @ids).send(method_name, *args)
  return normals unless @ids.include? nil

  used = @base.send(method_name, *args)
  # return those in normals AND those in parent scope not belonging to another
  normals.disjunct(used.relative_complement(@parent_scope))
end