Class: Datagrid::Filters::FilterEval
- Inherits:
-
Object
- Object
- Datagrid::Filters::FilterEval
- Defined in:
- lib/datagrid/filters/filter_eval.rb
Overview
ActiveRecord is a little brain fuck. We can not call instance_eval on ActiveRecord::Relation class because it will automatically convert it to an array because #instance_eval is not included in the method list that do not cause force result loading That is why we need thi helper class
Instance Method Summary collapse
-
#initialize(filter, scope, value) ⇒ FilterEval
constructor
A new instance of FilterEval.
- #method_missing(meth, *args, &blk) ⇒ Object
- #run ⇒ Object
Constructor Details
#initialize(filter, scope, value) ⇒ FilterEval
Returns a new instance of FilterEval.
8 9 10 11 12 |
# File 'lib/datagrid/filters/filter_eval.rb', line 8 def initialize(filter, scope, value) @filter = filter @scope = scope @value = value end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &blk) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/datagrid/filters/filter_eval.rb', line 18 def method_missing(meth, *args, &blk) if @scope.respond_to?(meth) @scope.send(meth, *args, &blk) else super(meth, *args, &blk) end end |
Instance Method Details
#run ⇒ Object
14 15 16 |
# File 'lib/datagrid/filters/filter_eval.rb', line 14 def run instance_exec @value, &(@filter.block) end |