eBooru/app/inputs/form_field_collector.rb
Earlopain fc7d84affd
[RuboCop] Enable Style/FrozenStringLiteralComment
This reduces allocations on the posts page by about 5%, from basic testing
2024-02-25 18:15:55 +01:00

27 lines
478 B
Ruby

# frozen_string_literal: true
# Captures all the input names used in a form block
class FormFieldCollector
attr_reader :fields
def initialize
@fields = []
end
def input(input_name, **)
@fields.push(input_name)
end
def user(input_prefix, **)
if input_prefix.is_a?(Array)
@fields.push(*input_prefix)
else
@fields.push(:"#{input_prefix}_id", :"#{input_prefix}_name")
end
end
# Swallow the rest
def method_missing(*)
end
end