Class: Generators::Custom
- Inherits:
-
Base
- Object
- Base
- Generators::Custom
show all
- Defined in:
- lib/toschas/filterable/generators/custom.rb
Instance Attribute Summary
Attributes inherited from Base
#filters, #model, #options
Instance Method Summary
collapse
Methods inherited from Base
#initialize
Instance Method Details
#custom_prefixes ⇒ Object
16
17
18
19
|
# 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) ⇒ Object
21
22
23
|
# File 'lib/toschas/filterable/generators/custom.rb', line 21
def ensure_prefix_array(prefix)
prefix.is_a?(Array) ? prefix.reject(&:blank?) : [prefix]
end
|
#generate ⇒ Object
3
4
5
6
7
8
9
10
11
12
13
14
|
# 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
|