Class: SolidusGraphqlApi::Generators::InstallGenerator

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

Constant Summary collapse

MOUNT_GRAPHQL_ENGINE =
"mount SolidusGraphqlApi::Engine, at: '/graphql'"

Instance Method Summary collapse

Instance Method Details

#add_migrationsObject



16
17
18
# File 'lib/generators/solidus_graphql_api/install/install_generator.rb', line 16

def add_migrations
  run 'bin/rails railties:install:migrations FROM=solidus_graphql_api'
end

#copy_initializerObject



12
13
14
# File 'lib/generators/solidus_graphql_api/install/install_generator.rb', line 12

def copy_initializer
  template 'initializer.rb', 'config/initializers/solidus_graphql_api.rb'
end

#install_routesObject



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/generators/solidus_graphql_api/install/install_generator.rb', line 29

def install_routes
  if Pathname(app_path).join('config', 'routes.rb').read.include? MOUNT_GRAPHQL_ENGINE
    say_status :route_exist, MOUNT_GRAPHQL_ENGINE, :blue
  else
    route <<~RUBY
      # This line installs graphql's main route to execute queries

      mount SolidusGraphqlApi::Engine, at: '/graphql'
    RUBY
  end
end

#run_migrationsObject



20
21
22
23
24
25
26
27
# File 'lib/generators/solidus_graphql_api/install/install_generator.rb', line 20

def run_migrations
  run_migrations = options[:auto_run_migrations] || ['', 'y', 'Y'].include?(ask('Would you like to run the migrations now? [Y/n]')) # rubocop:disable Layout/LineLength
  if run_migrations
    run 'bin/rails db:migrate'
  else
    puts 'Skipping bin/rails db:migrate, don\'t forget to run it!' # rubocop:disable Rails/Output
  end
end