Class: LcpRuby::Generators::HostControllerGenerator

Inherits:
Rails::Generators::NamedBase
  • Object
show all
Defined in:
lib/generators/lcp_ruby/host_controller_generator.rb

Constant Summary collapse

VALID_ACTIONS =
%w[index show new create edit update destroy].freeze
CONCERN_ALIASES =

Concern short names → module names (in dependency order)

{
  "errors" => %w[ErrorHandling],
  "setup"  => %w[PresenterSetup],
  "auth"   => %w[Authentication Impersonation Authorization],
  "paths"  => %w[PathHelpers],
  "views"  => %w[ViewHelpers],
  "search" => %w[Search],
  "crud"   => %w[CrudHelpers]
}.freeze
CONCERN_ORDER =

Topological order — includes must be emitted in this sequence

%w[
  ErrorHandling
  Authentication
  PresenterSetup
  Impersonation
  Authorization
  PathHelpers
  ViewHelpers
  Search
  CrudHelpers
].freeze
CONCERN_DEPS =

Implicit dependencies: if X is included, these must also be included

{
  "Impersonation"  => %w[Authentication PresenterSetup],
  "Authorization"  => %w[PresenterSetup Authentication],
  "PathHelpers"    => %w[PresenterSetup],
  "ViewHelpers"    => %w[PresenterSetup],
  "Search"         => %w[PresenterSetup Authorization],
  "CrudHelpers"    => %w[PresenterSetup Authorization]
}.freeze

Instance Method Summary collapse

Instance Method Details

#create_controllerObject



55
56
57
# File 'lib/generators/lcp_ruby/host_controller_generator.rb', line 55

def create_controller
  template "controller.rb.erb", "app/controllers/#{file_name.pluralize}_controller.rb"
end

#create_view_stubsObject



59
60
61
62
63
64
65
66
67
68
# File 'lib/generators/lcp_ruby/host_controller_generator.rb', line 59

def create_view_stubs
  return unless options[:views] == "custom"

  selected_actions.each do |action|
    next unless %w[index show new edit].include?(action)

    create_file "app/views/#{file_name.pluralize}/#{action}.html.erb",
      "<%# TODO: #{action} view for #{class_name.pluralize} %>\n"
  end
end

#show_post_install_messageObject



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/generators/lcp_ruby/host_controller_generator.rb', line 70

def show_post_install_message
  say ""
  say "Host controller generated!", :green
  say ""
  say "Generated: app/controllers/#{file_name.pluralize}_controller.rb"
  if options[:views] == "custom"
    say "Generated: app/views/#{file_name.pluralize}/ (view stubs)"
  end
  say ""
  say "Next steps:", :yellow
  say "  Add to your presenter YAML:"
  say ""
  say "    controller: \"#{file_name.pluralize}\""
  say ""
  say "  Or for per-action overrides:"
  say ""
  say "    action_controllers:"
  selected_actions.each do |action|
    say "      #{action}: \"#{file_name.pluralize}##{action}\""
  end
  say ""
end