Class: Archangel::Generators::InstallGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- Archangel::Generators::InstallGenerator
- Defined in:
- lib/generators/archangel/install/install_generator.rb
Overview
Archangel install generator
Instance Method Summary collapse
-
#add_archangel_seed ⇒ Object
Append Archangel seeds to seed file.
-
#add_files ⇒ Object
Copy files.
-
#add_vendor_files ⇒ Object
Copy vendor files for Archangel extensions.
-
#banner ⇒ Object
After install message.
-
#create_database ⇒ Object
Create database is needed.
-
#create_seeds_file ⇒ Object
Create seed file if needed.
-
#insert_routes ⇒ Object
Insert Archangel routes.
-
#install_migrations ⇒ Object
Install Archangel migrations.
-
#prevent_nested_install ⇒ Object
Do not allowing running the generator within the gem.
-
#run_migrations ⇒ Object
Run Archangel migrations.
-
#seed_database ⇒ Object
Seed database.
Instance Method Details
#add_archangel_seed ⇒ Object
Append Archangel seeds to seed file
82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/generators/archangel/install/install_generator.rb', line 82 def add_archangel_seed return unless [:seed] say_quietly "Seeding local seeds.rb..." append_file "db/seeds.rb", " # Archangel seed data\n Archangel::Engine.load_seed\n\n SEEDS\nend\n".strip_heredoc |
#add_files ⇒ Object
Copy files
46 47 48 49 50 51 52 53 |
# File 'lib/generators/archangel/install/install_generator.rb', line 46 def add_files say_quietly "Copying files..." %w[ .env.sample config/initializers/carrierwave.rb config/initializers/devise.rb config/archangel.yml ].each { |file| template file } end |
#add_vendor_files ⇒ Object
Copy vendor files for Archangel extensions
58 59 60 61 62 63 64 65 |
# File 'lib/generators/archangel/install/install_generator.rb', line 58 def add_vendor_files say_quietly "Copying files..." %w[auth backend frontend].each do |section| template "vendor/assets/javascripts/archangel/#{section}.js" template "vendor/assets/stylesheets/archangel/#{section}.css" end end |
#banner ⇒ Object
After install message
154 155 156 157 |
# File 'lib/generators/archangel/install/install_generator.rb', line 154 def say_quietly "*" * 80 say_quietly " Done, sir! Done! Archangel has been installed!" end |
#create_database ⇒ Object
Create database is needed
104 105 106 |
# File 'lib/generators/archangel/install/install_generator.rb', line 104 def create_database say_with_task("Creating database...", "db:create") end |
#create_seeds_file ⇒ Object
Create seed file if needed
70 71 72 73 74 75 76 77 |
# File 'lib/generators/archangel/install/install_generator.rb', line 70 def create_seeds_file return unless [:seed] return if File.exist?(File.join(destination_root, "db", "seeds.rb")) say_quietly "Creating db/seeds.rb file..." create_file "db/seeds.rb" end |
#insert_routes ⇒ Object
Insert Archangel routes
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/generators/archangel/install/install_generator.rb', line 133 def insert_routes say_quietly "Adding Archangel routes..." insert_into_file(File.join("config", "routes.rb"), after: "Rails.application.routes.draw do\n") do " # This mounts Archangel's routes at the root of your application. If you would\n # like to change where the engine is mounted, simply change the :at option to\n # reflect your needs.\n #\n mount Archangel::Engine, at: \"/\#{options[:route_path]}\"\n\n ROUTES\n end\n\n say_quietly \"Your application's config/routes.rb has been updated.\"\nend\n".strip_heredoc.indent(2) |
#install_migrations ⇒ Object
Install Archangel migrations
97 98 99 |
# File 'lib/generators/archangel/install/install_generator.rb', line 97 def install_migrations say_with_task("Installing migrations...", "railties:install:migrations") end |
#prevent_nested_install ⇒ Object
Do not allowing running the generator within the gem
37 38 39 40 41 |
# File 'lib/generators/archangel/install/install_generator.rb', line 37 def prevent_nested_install return unless Rails.try(:root) && Rails.root.blank? abort "Install generator cannot be run inside Archangel extension." end |
#run_migrations ⇒ Object
Run Archangel migrations
111 112 113 114 115 116 117 |
# File 'lib/generators/archangel/install/install_generator.rb', line 111 def run_migrations if [:migrate] say_with_task("Running migrations...", "db:migrate") else say_quietly "Skipping migrations. Run `rake db:migrate` yourself." end end |
#seed_database ⇒ Object
Seed database
122 123 124 125 126 127 128 |
# File 'lib/generators/archangel/install/install_generator.rb', line 122 def seed_database if [:migrate] && [:seed] say_with_task("Inseminating...", "db:seed #{rake_seed_options}") else say_quietly "Skipping seed data. Run `rake db:seed` yourself." end end |