Class: Archangel::Generators::InstallGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/archangel/install/install_generator.rb

Overview

Archangel install generator

Instance Method Summary collapse

Instance Method Details

#add_archangel_seedObject

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 options[: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_filesObject

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_filesObject

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

After install message



154
155
156
157
# File 'lib/generators/archangel/install/install_generator.rb', line 154

def banner
  say_quietly "*" * 80
  say_quietly "  Done, sir! Done! Archangel has been installed!"
end

#create_databaseObject

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_fileObject

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 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_routesObject

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_migrationsObject

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_installObject

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_migrationsObject

Run Archangel migrations



111
112
113
114
115
116
117
# 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_databaseObject

Seed database



122
123
124
125
126
127
128
# 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