Class: BoNamespaceGenerator

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

Instance Method Summary collapse

Instance Method Details

#add_seed_fileObject



25
26
27
28
29
# File 'lib/generators/bo_namespace/bo_namespace_generator.rb', line 25

def add_seed_file
  inject_into_file 'db/seeds.rb' do 
    "require_relative 'seeds/#{plural_name}.rb'\n"
  end
end

#create_bo_namespace_filesObject



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/generators/bo_namespace/bo_namespace_generator.rb', line 7

def create_bo_namespace_files
  run "bundle exec rails g devise #{file_name.capitalize}"
  run 'bundle exec rails db:migrate'
  create_routes_and_views
  template 'admin.html.erb', File.join('app/views/layouts/', "#{singular_name}.html.erb")
  template 'admin_controller.rb', File.join('app/controllers/', "#{singular_name}_controller.rb")
  template 'seeds.rb', File.join('db/seeds/', "#{plural_name}.rb")
  template 'side_bar.html.erb', File.join('app/views/', "#{plural_name}/layouts/_side_bar.html.erb")
  create_translations
  remove_devise_registration
end

#create_directoriesObject



19
20
21
22
23
# File 'lib/generators/bo_namespace/bo_namespace_generator.rb', line 19

def create_directories
  ["app/views/#{plural_name}", "app/controllers/#{plural_name}"].each do |dir|
    FileUtils.mkdir(dir) unless File.directory?(dir)
  end
end