Sha256: 7983ebf222bb4ee4839ab42cb2fe3ab28d8a7fc0a894511a414dc43fef010ff4

Contents?: true

Size: 771 Bytes

Versions: 1

Compression:

Stored size: 771 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 parse(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
    unless self.prompt
      self.options.has_key?(:include_blank) ? options[:include_blank] : !multiple
    end
  end
  
  def prompt
    self.options.has_key?(:prompt) ? options[:prompt] : false
  end

  def strict
    self.options[:strict]
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
datagrid-0.9.0 lib/datagrid/filters/enum_filter.rb