Sha256: 1e05dd5857a8f7129df68e8cc292a1c4eeea661b36c280c02a6f79e41f3e6248

Contents?: true

Size: 753 Bytes

Versions: 6

Compression:

Stored size: 753 Bytes

Contents

class Datagrid::Filters::EnumFilter < Datagrid::Filters::BaseFilter

  def initialize(*args)
    super(*args)
    raise Datagrid::ConfigurationError, ":select option not specified" unless options[:select]
  end

  def format(value)
    return nil if self.strict && !select.include?(value)
    value
  end

  def select(object = nil)
    option = self.options[:select]
    if option.respond_to?(:call)
      option.arity == 1 ? option.call(object) : option.call
    else
      option
    end
  end

  def include_blank
    self.options.has_key?(:include_blank) ? options[:include_blank] : true unless self.prompt
  end
  
  def prompt
    self.options.has_key?(:prompt) ? options[:prompt] : false
  end

  def strict
    self.options[:strict]
  end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
datagrid-0.8.2 lib/datagrid/filters/enum_filter.rb
datagrid-0.8.1 lib/datagrid/filters/enum_filter.rb
datagrid-0.8.0 lib/datagrid/filters/enum_filter.rb
datagrid-0.7.1 lib/datagrid/filters/enum_filter.rb
datagrid-0.7.0 lib/datagrid/filters/enum_filter.rb
datagrid-0.6.4 lib/datagrid/filters/enum_filter.rb