Class: Devformance::Generators::InstallGenerator

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.next_migration_number(dir) ⇒ Object



13
14
15
# File 'lib/generators/devformance/install/install_generator.rb', line 13

def self.next_migration_number(dir)
  Time.now.utc.strftime("%Y%m%d%H%M%S")
end

Instance Method Details

#copy_migrationsObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/generators/devformance/install/install_generator.rb', line 21

def copy_migrations
  migration_template(
    "create_performance_runs.rb.erb",
    "db/migrate/create_performance_runs.rb"
  )
  sleep 1
  migration_template(
    "create_slow_queries.rb.erb",
    "db/migrate/create_slow_queries.rb"
  )
  sleep 1
  migration_template(
    "add_run_id_to_slow_queries.rb.erb",
    "db/migrate/add_run_id_to_slow_queries.rb"
  )
  sleep 1
  migration_template(
    "add_columns_to_slow_queries.rb.erb",
    "db/migrate/add_columns_to_slow_queries.rb"
  )
  sleep 1
  migration_template(
    "create_devformance_runs.rb.erb",
    "db/migrate/create_devformance_runs.rb"
  )
  sleep 1
  migration_template(
    "create_devformance_file_results.rb.erb",
    "db/migrate/create_devformance_file_results.rb"
  )
end

#create_initializerObject



17
18
19
# File 'lib/generators/devformance/install/install_generator.rb', line 17

def create_initializer
  template "initializer.rb", "config/initializers/devformance.rb"
end

#mount_instructionsObject



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/generators/devformance/install/install_generator.rb', line 53

def mount_instructions
  route_exists = File.read("config/routes.rb").include?("devformance")
  if route_exists
    say "\n  Devformance is already mounted in config/routes.rb\n", :green
  else
    say "\n  Add this line to your config/routes.rb:\n\n", :yellow
    say "    mount ::Devformance::Engine, at: \"/devformance\"\n\n", :cyan
    say "  Then visit http://localhost:3000/devformance\n\n", :green
  end

  say "  If you use RSpec, tag your request specs to instrument them:\n\n"
  say "    require 'devformance'\n"
  say "    RSpec.describe 'Posts API', devformance: true do\n"
  say "      ...\n"
  say "    end\n\n"

  say "  Then run: bin/rails db:migrate\n", :green
end