Class: Madmin::Generators::ResourceGenerator

Inherits:
Rails::Generators::NamedBase
  • Object
show all
Includes:
Madmin::GeneratorHelpers
Defined in:
lib/generators/madmin/resource/resource_generator.rb

Constant Summary

Constants included from Madmin::GeneratorHelpers

Madmin::GeneratorHelpers::ROUTES_FILE

Instance Method Summary collapse

Methods included from Madmin::GeneratorHelpers

#call_generator, #optimize_indentation, #rails6_1_and_up?, #route, #route_namespace_exists?

Instance Method Details

#eager_loadObject



8
9
10
# File 'lib/generators/madmin/resource/resource_generator.rb', line 8

def eager_load
  Rails.application.eager_load!
end

#generate_controllerObject



16
17
18
19
# File 'lib/generators/madmin/resource/resource_generator.rb', line 16

def generate_controller
  destination = Rails.root.join("app/controllers/madmin/#{file_path.pluralize}_controller.rb")
  template("controller.rb", destination)
end

#generate_resourceObject



12
13
14
# File 'lib/generators/madmin/resource/resource_generator.rb', line 12

def generate_resource
  template "resource.rb", "app/madmin/resources/#{file_path}_resource.rb"
end

#generate_routeObject



21
22
23
24
25
26
27
# File 'lib/generators/madmin/resource/resource_generator.rb', line 21

def generate_route
  if route_namespace_exists?
    route "resources :#{plural_name}", namespace: class_path, indentation: separated_routes_file? ? 2 : 4, sentinel: /namespace :madmin do\s*\n/m
  else
    route "resources :#{plural_name}", namespace: [:madmin] + class_path
  end
end