Class: Charming::Generators::ControllerGenerator

Inherits:
AppFileGenerator show all
Defined in:
lib/charming/generators/controller_generator.rb

Overview

ControllerGenerator implements ‘charming generate controller NAME [ACTION …]`. Writes `app/controllers/<name>_controller.rb` containing a class that inherits from the app’s ‘ApplicationController` and a `show` (or named) action that renders the conventional view with the command palette passed as an assign.

Instance Method Summary collapse

Constructor Details

#initialize(name, args, out:, destination:, force: false) ⇒ ControllerGenerator

name is the resource name. args is the list of action names (defaults to ‘show`). out, destination, and force are forwarded to the parent.



12
13
14
15
# File 'lib/charming/generators/controller_generator.rb', line 12

def initialize(name, args, out:, destination:, force: false)
  super
  @actions = args
end

Instance Method Details

#generateObject

Writes the controller file to the standard app/controllers path.



18
19
20
# File 'lib/charming/generators/controller_generator.rb', line 18

def generate
  create_file(app_path("app", "controllers"), controller)
end