Class: Infold::SearchFormWriter
- Inherits:
-
BaseWriter
- Object
- BaseWriter
- Infold::SearchFormWriter
- Defined in:
- lib/infold/writers/search_form_writer.rb
Instance Attribute Summary
Attributes inherited from BaseWriter
Instance Method Summary collapse
-
#initialize(resource) ⇒ SearchFormWriter
constructor
A new instance of SearchFormWriter.
- #record_search_includes_code ⇒ Object
- #set_conditions_code ⇒ Object
Methods inherited from BaseWriter
#edit_path, #indent, #index_path, #new_path, #resource_name, #show_path
Constructor Details
#initialize(resource) ⇒ SearchFormWriter
Returns a new instance of SearchFormWriter.
6 7 8 |
# File 'lib/infold/writers/search_form_writer.rb', line 6 def initialize(resource) @resource = resource end |
Instance Method Details
#record_search_includes_code ⇒ Object
17 18 19 20 21 |
# File 'lib/infold/writers/search_form_writer.rb', line 17 def record_search_includes_code # includes belongs_to associations includes = @resource.associations&.select(&:belongs_to?) ".includes(:#{includes.map(&:name).join(', :')})" if includes.present? end |
#set_conditions_code ⇒ Object
10 11 12 13 14 15 |
# File 'lib/infold/writers/search_form_writer.rb', line 10 def set_conditions_code fields = @resource.conditions&.map{ |c| ":#{c.field.name}_#{c.sign}" }&.uniq return if fields.blank? code = "set_condition #{fields.join(",\n[TAB][TAB][TAB][TAB][TAB][TAB][TAB]")}\n" indent(code, 2).presence end |