Class: Generators::Simple

Inherits:
Base
  • Object
show all
Defined in:
lib/toschas/filterable/generators/simple.rb

Instance Attribute Summary

Attributes inherited from Base

#filters, #model, #options

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Generators::Base

Instance Method Details

#generateObject



3
4
5
6
7
8
9
10
11
12
# File 'lib/toschas/filterable/generators/simple.rb', line 3

def generate
  filters.each do |filter|
    model.define_singleton_method(
      "by_#{filter}", 
      ->(value) { send(:where, { filter => value }) }
    )

    generate_range_filter(filter) if table_loaded? && range_filter?(filter)
  end
end