Class: Hibiki::Rails::Generators::MultiselectGenerator

Inherits:
Rails::Generators::NamedBase
  • Object
show all
Includes:
ActiveRecord::Generators::Migration, GeneratorHelpers, MultiselectHelpers, MultiselectInjections, ScaffoldHelpers, ScaffoldModelInjection, ScaffoldPhlexHelpers, ScaffoldViewHelpers, Rails::Generators::ResourceHelpers
Defined in:
lib/generators/hibiki/rails/multiselect/multiselect_generator.rb

Overview

A dropdown multi-select over a has_many :through, added onto a resource hibiki:rails:scaffold_controller already generated: a channel concern that wraps the graph (the include line is the channel's only edit), a view partial or component riding the extras: hash, an ids signal on the ReactiveForm, and the join model when it doesn't exist yet.

Owner and target must exist and be migrated; the join is the one model this generator may create.

Constant Summary

Constants included from MultiselectInjections

Hibiki::Rails::Generators::MultiselectInjections::CHANNEL_ANCHOR, Hibiki::Rails::Generators::MultiselectInjections::ERB_FIELDSET_CLOSE, Hibiki::Rails::Generators::MultiselectInjections::FORM_ANCHOR, Hibiki::Rails::Generators::MultiselectInjections::PHLEX_FIELDSET_CLOSE, Hibiki::Rails::Generators::MultiselectInjections::ROW_ACTIONS_ANCHOR_ERB, Hibiki::Rails::Generators::MultiselectInjections::ROW_ACTIONS_ANCHOR_PHLEX

Constants included from ScaffoldPhlexHelpers

ScaffoldPhlexHelpers::HELPER_MODULES, ScaffoldPhlexHelpers::PHLEX_BASE, ScaffoldPhlexHelpers::PHLEX_INITIALIZER, ScaffoldPhlexHelpers::PHLEX_NAMESPACE, ScaffoldPhlexHelpers::PLAIN_TYPES

Constants included from ScaffoldViewHelpers

ScaffoldViewHelpers::FIELD_TOKENS

Constants included from GeneratorHelpers

GeneratorHelpers::APPLICATION_HELPER, GeneratorHelpers::IMPORTMAP, GeneratorHelpers::INDEX_JS, GeneratorHelpers::REGISTER_FRAGMENT, GeneratorHelpers::SHIM

Instance Method Summary collapse

Instance Method Details

#create_concernObject



81
82
83
# File 'lib/generators/hibiki/rails/multiselect/multiselect_generator.rb', line 81

def create_concern
  template "concern.rb.tt", concern_path
end

#create_join_modelObject



69
70
71
72
73
74
# File 'lib/generators/hibiki/rails/multiselect/multiselect_generator.rb', line 69

def create_join_model
  return unless (@join_generated = join_missing?)

  template "join_model.rb.tt", join_model_path
  migration_template "join_migration.rb.tt", "db/migrate/create_#{join_table_name}.rb"
end

#create_viewObject



93
94
95
96
97
98
99
# File 'lib/generators/hibiki/rails/multiselect/multiselect_generator.rb', line 93

def create_view
  if phlex?
    template "multiselect_component.rb.tt", view_path("#{multiselect_partial}.rb")
  else
    template "_multiselect.html.erb.tt", view_path("_#{multiselect_partial}.html.erb")
  end
end

#post_installObject



117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/generators/hibiki/rails/multiselect/multiselect_generator.rb', line 117

def post_install
  if @join_generated
    say_status :migrate, "#{join_class_name} was generated — run bin/rails db:migrate " \
                         "before using the multiselect.", :yellow
  end
  if @concerns_dir_new
    say_status :restart, "app/channels/concerns is new. " \
                         "Please restart if the server is running.", :yellow
  end
  say_status :assoc, "using #{target_class_name}##{label_column} as the option label — " \
                     "pass --label=<column> if that's wrong", :blue
end

#preflightObject

Everything that can refuse, before anything is written.



60
61
62
63
64
65
66
67
# File 'lib/generators/hibiki/rails/multiselect/multiselect_generator.rb', line 60

def preflight
  owner_class
  target_class
  check_scaffolded!
  label_column
  join_class_name
  @concerns_dir_new = !exists?("app/channels/concerns")
end

#thread_extrasObject

BEFORE the render injection: the compat probe reads "extras" from the row form, and the render line would satisfy it vacuously.



103
104
105
# File 'lib/generators/hibiki/rails/multiselect/multiselect_generator.rb', line 103

def thread_extras
  thread_extras_through_partials
end

#wire_channelObject



85
86
87
# File 'lib/generators/hibiki/rails/multiselect/multiselect_generator.rb', line 85

def wire_channel
  inject_channel_include
end

#wire_formObject



89
90
91
# File 'lib/generators/hibiki/rails/multiselect/multiselect_generator.rb', line 89

def wire_form
  inject_form_association
end

#wire_modelsObject



76
77
78
79
# File 'lib/generators/hibiki/rails/multiselect/multiselect_generator.rb', line 76

def wire_models
  inject_owner_associations
  inject_join_touch
end

#wire_preloadsObject



112
113
114
115
# File 'lib/generators/hibiki/rails/multiselect/multiselect_generator.rb', line 112

def wire_preloads
  inject_query_preload
  inject_member_channel_preload
end

#wire_viewsObject



107
108
109
110
# File 'lib/generators/hibiki/rails/multiselect/multiselect_generator.rb', line 107

def wire_views
  inject_row_form_render
  inject_row_display
end