Module: Hibiki::Rails::Generators::UploadFieldInjections

Included in:
UploadFieldGenerator
Defined in:
lib/generators/hibiki/rails/upload_field_injections.rb

Overview

What hibiki:rails:upload_field writes into files the app already owns. Every injection is guarded by a wired? probe, so a re-run is a no-op, and every missing anchor downgrades to a manual_wiring notice rather than a half-edit.

Constant Summary collapse

CHANNEL_ANCHOR =

The anchors, all text the scaffold templates emit verbatim. Thor's insert_into_file replaces EVERY match, so each anchor must occur exactly once in its file — never a bare "

", which the row form closes two blocks with.

"  include Hibiki::Rails::Channel\n"
ERB_FIELDSET_CLOSE =

The fieldset's close: the one "

" a blank line follows (the form-actions close runs straight into the ERB end, and a boolean field's wrap closes at four spaces, which a bare-string anchor matched as a substring).

%r{^  </div>\n\n}
PHLEX_FIELDSET_CLOSE =
"      end\n\n      form_actions"
ROW_ACTIONS_ANCHOR_ERB =

Line-anchored for the same reason: a boolean field guards its toggle with the same text two spaces deeper.

/^ {4}<% if actions %>/
ROW_ACTIONS_ANCHOR_PHLEX =
"    row_actions if @actions"
ERB_SUBMIT_DIV =
/^  <div>\n    <%= form\.submit/
PHLEX_PAGE_FIELDS_CALL =
/^      fields\(form\)\n/
FILE_END =

The class's own closing end — the only end at column zero.

/^end\n\z/
QUERY_WINDOW_SCOPE =

The query's window scope; the lazy middle tolerates any prior chain (the regex backtracks past includes(...)'s own parens).

/(def window_scope = self\.class\.window\(apply_sort\()(.*?)(\), page: @page\))/