Module: MightyGrid::Filters::ClassMethods

Defined in:
lib/mighty_grid/filters.rb

Instance Method Summary collapse

Instance Method Details

#filter(name, type = :string, options = {}, &block) ⇒ Object



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/mighty_grid/filters.rb', line 111

def filter(name, type = :string, options = {}, &block)
  name = name.to_sym

  unless self.mappings.key?(type)
    fail MightyGrid::Exceptions::ArgumentError.new("filter for the specified type isn't supported.")
  end

  if name.present? && self.filters.key?(name)
    fail MightyGrid::Exceptions::ArgumentError.new("filter with the specified name already exists.")
  else
    options.merge!(name: name)
    options.merge!(model: @klass) unless options.key?(:model)
    self.filters[name] = self.mappings[type].new(options, &block)
  end
end

#search(name) ⇒ Object



127
128
129
130
# File 'lib/mighty_grid/filters.rb', line 127

def search(name)
  filter(name, :search)
  self.search_name = name
end