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.
-
#disallow_robots ⇒ Object
Disallow backend indexing in robots.txt.
-
#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
98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/generators/archangel/install/install_generator.rb', line 98 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 54 55 56 57 |
# 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 do |file| template file end end |
#add_vendor_files ⇒ Object
Copy vendor files for Archangel extensions
62 63 64 65 66 67 68 69 |
# File 'lib/generators/archangel/install/install_generator.rb', line 62 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
178 179 180 181 |
# File 'lib/generators/archangel/install/install_generator.rb', line 178 def say_quietly "*" * 80 say_quietly " Done, sir! Done! Archangel has been installed!" end |
#create_database ⇒ Object
Create database is needed
122 123 124 125 126 |
# File 'lib/generators/archangel/install/install_generator.rb', line 122 def create_database say_quietly "Creating database..." silence_warnings { rake "db:create" } end |
#create_seeds_file ⇒ Object
Create seed file if needed
86 87 88 89 90 91 92 93 |
# File 'lib/generators/archangel/install/install_generator.rb', line 86 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 |
#disallow_robots ⇒ Object
Disallow backend indexing in robots.txt
74 75 76 77 78 79 80 81 |
# File 'lib/generators/archangel/install/install_generator.rb', line 74 def disallow_robots return unless File.exist? "public/robots.txt" append_file "public/robots.txt", " User-agent: *\n Disallow: /backend\n ROBOTS\nend\n".strip_heredoc |
#insert_routes ⇒ Object
Insert Archangel routes
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/generators/archangel/install/install_generator.rb', line 157 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
113 114 115 116 117 |
# File 'lib/generators/archangel/install/install_generator.rb', line 113 def install_migrations say_quietly "Installing migrations..." silence_warnings { rake "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
131 132 133 134 135 136 137 138 139 |
# File 'lib/generators/archangel/install/install_generator.rb', line 131 def run_migrations if [:migrate] say_quietly "Running migrations..." silence_warnings { rake "db:migrate" } else say_quietly "Skipping migrations. Run `rake db:migrate` yourself." end end |
#seed_database ⇒ Object
Seed database
144 145 146 147 148 149 150 151 152 |
# File 'lib/generators/archangel/install/install_generator.rb', line 144 def seed_database if [:migrate] && [:seed] say_quietly "Inseminating..." silence_warnings { rake "db:seed #{rake_seed_options}" } else say_quietly "Skipping seed data. Run `rake db:seed` yourself." end end |