Class: ActiveRecordEx::NillableFind::NillableArel
- Inherits:
-
Object
- Object
- ActiveRecordEx::NillableFind::NillableArel
- Defined in:
- lib/active-record-ex/nillable_find.rb
Instance Method Summary collapse
-
#initialize(base, ids, parent_scope) ⇒ NillableArel
constructor
A new instance of NillableArel.
- #method_missing(method_name, *args, &block) ⇒ Object
Constructor Details
#initialize(base, ids, parent_scope) ⇒ NillableArel
Returns a new instance of NillableArel.
4 5 6 7 8 |
# 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 |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
10 11 12 13 14 15 16 17 18 19 |
# 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 |