Class: SolidusSubscriptions::Generators::InstallGenerator

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

Instance Method Summary collapse

Instance Method Details

#add_javascriptsObject



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

def add_javascripts
  append_file 'vendor/assets/javascripts/spree/backend/all.js', "//= require spree/backend/solidus_subscriptions\n"
end

#add_migrationsObject



35
36
37
# File 'lib/generators/solidus_subscriptions/install/install_generator.rb', line 35

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

#copy_initializerObject



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

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

#copy_starter_frontend_filesObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/generators/solidus_subscriptions/install/install_generator.rb', line 20

def copy_starter_frontend_files
  return if options[:frontend] != 'starter'

  copy_file 'app/views/cart_line_items/_subscription_fields.html.erb'
  prepend_to_file 'app/views/cart_line_items/_product_submit.html.erb', "<%= render 'cart_line_items/subscription_fields' %>\n"

  copy_file 'app/controllers/concerns/create_subscription.rb'
  insert_into_file 'app/controllers/cart_line_items_controller.rb', after: "class CartLineItemsController < StoreController\n" do
    <<~RUBY.indent(2)
      include CreateSubscription

    RUBY
  end
end

#run_migrationsObject



39
40
41
42
43
44
45
46
# File 'lib/generators/solidus_subscriptions/install/install_generator.rb', line 39

def run_migrations
  run_migrations = options[:auto_run_migrations] || ['', 'y', 'Y'].include?(ask('Would you like to run the migrations now? [Y/n]'))
  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