class Generators::Custom

Public Instance Methods

custom_prefixes() click to toggle source
# File lib/toschas/filterable/generators/custom.rb, line 16
def custom_prefixes
  prefix = options[:prefix].blank? ? 'by' : options[:prefix]
  ensure_prefix_array(prefix)
end
ensure_prefix_array(prefix) click to toggle source
# File lib/toschas/filterable/generators/custom.rb, line 21
def ensure_prefix_array(prefix)
  prefix.is_a?(Array) ? prefix.reject(&:blank?) : [prefix]
end
generate() click to toggle source
# File lib/toschas/filterable/generators/custom.rb, line 3
def generate
  prefixes = custom_prefixes
  filters.each do |filter|
    prefixes.each do |prefix|
      filter_name = prefix == :none ? "#{filter}" : "#{prefix}_#{filter}"
      model.define_singleton_method(
        filter_name, 
        ->(_value) { send(:where, nil) }
      )
    end
  end
end