Sha256: 4de22498caea4a922bf727ebce0333aec05dedee028f8fb15769e743d604055a

Contents?: true

Size: 1.15 KB

Versions: 4

Compression:

Stored size: 1.15 KB

Contents

# frozen_string_literal: true

module SolidusActAsTenant
  module Generators
    class InstallGenerator < Rails::Generators::Base
      class_option :auto_run_migrations, type: :boolean, default: false
      source_root File.expand_path('templates', __dir__)

      def self.exit_on_failure?
        true
      end

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

      def copy_config
        template 'tenant_aware_models.yml', 'config/tenant_aware_models.yml'
      end

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

      def run_migrations
        puts 'Remember to inspect and adapt the migration files before migrating!' # rubocop:disable Rails/Output
        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
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
solidus_act_as_tenant-0.0.4 lib/generators/solidus_act_as_tenant/install/install_generator.rb
solidus_act_as_tenant-0.0.3 lib/generators/solidus_act_as_tenant/install/install_generator.rb
solidus_act_as_tenant-0.0.2 lib/generators/solidus_act_as_tenant/install/install_generator.rb
solidus_act_as_tenant-0.0.1 lib/generators/solidus_act_as_tenant/install/install_generator.rb