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


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

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_filesObject

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

After install message


178
179
180
181
# File 'lib/generators/archangel/install/install_generator.rb', line 178

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

#create_databaseObject

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_fileObject

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

#disallow_robotsObject

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", <<-ROBOTS.strip_heredoc
    User-agent: *
    Disallow: /backend
  ROBOTS
end

#insert_routesObject

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

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


131
132
133
134
135
136
137
138
139
# File 'lib/generators/archangel/install/install_generator.rb', line 131

def run_migrations
  if options[:migrate]
    say_quietly "Running migrations..."

    silence_warnings { rake "db:migrate" }
  else
    say_quietly "Skipping migrations. Run `rake db:migrate` yourself."
  end
end

#seed_databaseObject

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 options[:migrate] && options[: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