class Archangel::Generators::InstallGenerator
Archangel
install generator
Public Instance Methods
add_archangel_seed()
click to toggle source
Append Archangel
seeds to seed file
# File lib/generators/archangel/install/install_generator.rb, line 82 def add_archangel_seed return unless options[:seed] say_quietly "Seeding local seeds.rb..." append_file "db/seeds.rb", <<-SEEDS.strip_heredoc # Archangel seed data Archangel::Engine.load_seed SEEDS end
add_files()
click to toggle source
Copy files
# 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()
click to toggle source
Copy vendor files for Archangel
extensions
# 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
create_database()
click to toggle source
Create database is needed
# File lib/generators/archangel/install/install_generator.rb, line 104 def create_database say_with_task("Creating database...", "db:create") end
create_seeds_file()
click to toggle source
Create seed file if needed
# File lib/generators/archangel/install/install_generator.rb, line 70 def create_seeds_file return unless options[: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()
click to toggle source
Insert Archangel
routes
# 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 <<-ROUTES.strip_heredoc.indent(2) # This mounts Archangel's routes at the root of your application. If you would # like to change where the engine is mounted, simply change the :at option to # reflect your needs. # mount Archangel::Engine, at: "/#{options[:route_path]}" ROUTES end say_quietly "Your application's config/routes.rb has been updated." end
install_migrations()
click to toggle source
Install Archangel
migrations
# 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()
click to toggle source
Do not allowing running the generator within the gem
# 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()
click to toggle source
Run Archangel
migrations
# File lib/generators/archangel/install/install_generator.rb, line 111 def run_migrations if options[:migrate] say_with_task("Running migrations...", "db:migrate") else say_quietly "Skipping migrations. Run `rake db:migrate` yourself." end end
seed_database()
click to toggle source
Seed database
# File lib/generators/archangel/install/install_generator.rb, line 122 def seed_database if options[:migrate] && options[:seed] say_with_task("Inseminating...", "db:seed #{rake_seed_options}") else say_quietly "Skipping seed data. Run `rake db:seed` yourself." end end
Protected Instance Methods
rake_seed_options()
click to toggle source
# File lib/generators/archangel/install/install_generator.rb, line 162 def rake_seed_options fields = %w[admin_email admin_name admin_password admin_username] fields.map do |field| field_option = options[field.to_sym] "#{field.upcase}=#{field_option}" if field_option.present? end.compact.join(" ") end
say_quietly(message)
click to toggle source
# File lib/generators/archangel/install/install_generator.rb, line 178 def say_quietly(message) say(message) unless options[:quiet] end
say_with_task(message, task)
click to toggle source
# File lib/generators/archangel/install/install_generator.rb, line 172 def say_with_task(message, task) say_quietly message silence_warnings { rake task } end