Sha256: 91d075e4a8382b93c5967e9fe7f9a8ab981ea03e8d6d3137c7d1c575936b8bfd

Contents?: true

Size: 803 Bytes

Versions: 1

Compression:

Stored size: 803 Bytes

Contents

require "datagrid/filters/filter_eval"

class Datagrid::Filters::BaseFilter

  attr_accessor :grid, :options, :block, :name

  def initialize(grid, name, options = {}, &block)
    self.grid = grid
    self.name = name
    self.options = options
    self.block = block
  end

  def apply(scope, value)
    return scope if value.nil? && !options[:allow_nil]
    return scope if value.blank? && !options[:allow_blank]
    ::Datagrid::Filters::FilterEval.new(self, scope, value).run
  end

  def format(value)
    raise NotImplementedError, "#format(value) suppose to be overwritten"
  end

  def header
    I18n.translate(self.name, :scope => "datagrid.#{grid.class.to_s.underscore.split("/").last}.filters", :default => self.name.to_s.humanize)
  end

  def default
    self.options[:default]
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
datagrid-0.0.3 lib/datagrid/filters/base_filter.rb