Class: Koi::AdminRouteGenerator

Inherits:
Rails::Generators::NamedBase
  • Object
show all
Includes:
Rails::Generators::ResourceHelpers
Defined in:
lib/generators/koi/admin_route/admin_route_generator.rb

Instance Method Summary collapse

Instance Method Details

#add_navigationObject



28
29
30
31
32
33
# File 'lib/generators/koi/admin_route/admin_route_generator.rb', line 28

def add_navigation
  insert_into_file("config/initializers/koi.rb",
                   "  \"#{[*regular_class_path.map(&:humanize),
                           human_name.pluralize].join(' ')}\" => \"/admin#{route_url}\",\n",
                   after: "Koi::Menu.modules = {\n")
end

#add_routeObject



18
19
20
# File 'lib/generators/koi/admin_route/admin_route_generator.rb', line 18

def add_route
  route "resources :#{file_name.pluralize}", namespace: regular_class_path
end

#create_navigationObject



22
23
24
25
26
# File 'lib/generators/koi/admin_route/admin_route_generator.rb', line 22

def create_navigation
  return if Pathname.new(destination_root).join("config/initializers/koi.rb").exist?

  template("initializer.rb", "config/initializers/koi.rb")
end

#create_routesObject



12
13
14
15
16
# File 'lib/generators/koi/admin_route/admin_route_generator.rb', line 12

def create_routes
  return if Pathname.new(destination_root).join("config/routes/admin.rb").exist?

  template("routes.rb", "config/routes/admin.rb")
end