Sha256: 8ad62954d6160c9c5cd7d421bc94c1336e77c5256fd73056257b6d49307e1898

Contents?: true

Size: 751 Bytes

Versions: 4

Compression:

Stored size: 751 Bytes

Contents

# 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 this helper class
class Datagrid::Filters::FilterEval

  attr_accessor :filter, :scope, :value

  def initialize(filter, scope, value)
    @filter = filter
    @scope = scope
    @value = value
  end

  def run
    instance_exec @value, &(@filter.block)
  end

  def driver
    @filter.grid.driver
  end

  def method_missing(meth, *args, &blk)
    if @scope.respond_to?(meth)
      @scope.send(meth, *args, &blk)
    else
      super(meth, *args, &blk)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
datagrid-0.5.4 lib/datagrid/filters/filter_eval.rb
datagrid-0.5.3 lib/datagrid/filters/filter_eval.rb
datagrid-0.5.2 lib/datagrid/filters/filter_eval.rb
datagrid-0.5.1 lib/datagrid/filters/filter_eval.rb