class Solidus::InstallGenerator

@private

Constants

CORE_MOUNT_ROUTE
PAYMENT_METHODS

Public Class Methods

source_paths() click to toggle source
# File lib/generators/solidus/install/install_generator.rb, line 32
def self.source_paths
  paths = superclass.source_paths
  paths << File.expand_path('../templates', "../../#{__FILE__}")
  paths << File.expand_path('../templates', "../#{__FILE__}")
  paths << File.expand_path('templates', __dir__)
  paths.flatten
end

Public Instance Methods

add_files() click to toggle source
# File lib/generators/solidus/install/install_generator.rb, line 51
def add_files
  template 'config/initializers/spree.rb.tt', 'config/initializers/spree.rb'
end
additional_tweaks() click to toggle source
# File lib/generators/solidus/install/install_generator.rb, line 65
    def additional_tweaks
      return unless File.exist? 'public/robots.txt'

      append_file "public/robots.txt", <<-ROBOTS.strip_heredoc
        User-agent: *
        Disallow: /checkout
        Disallow: /cart
        Disallow: /orders
        Disallow: /user
        Disallow: /account
        Disallow: /api
        Disallow: /password
      ROBOTS
    end
complete() click to toggle source
# File lib/generators/solidus/install/install_generator.rb, line 249
def complete
  unless options[:quiet]
    puts "*" * 50
    puts "Solidus has been installed successfully. You're all ready to go!"
    puts " "
    puts "Enjoy!"
  end
end
configure_application() click to toggle source
# File lib/generators/solidus/install/install_generator.rb, line 105
    def configure_application
      application <<-RUBY
    # Load application's model / class decorators
    initializer 'spree.decorators' do |app|
      config.to_prepare do
        Dir.glob(Rails.root.join('app/**/*_decorator*.rb')) do |path|
          require_dependency(path)
        end
      end
    end
      RUBY

      if !options[:enforce_available_locales].nil?
        application <<-RUBY
    # Prevent this deprecation message: https://github.com/svenfuchs/i18n/commit/3b6e56e
    I18n.enforce_available_locales = #{options[:enforce_available_locales]}
        RUBY
      end
    end
create_database() click to toggle source
# File lib/generators/solidus/install/install_generator.rb, line 174
def create_database
  say_status :creating, "database"
  rake 'db:create'
end
create_overrides_directory() click to toggle source
# File lib/generators/solidus/install/install_generator.rb, line 101
def create_overrides_directory
  empty_directory "app/overrides"
end
include_seed_data() click to toggle source
# File lib/generators/solidus/install/install_generator.rb, line 161
    def include_seed_data
      append_file "db/seeds.rb", <<-RUBY.strip_heredoc

        Spree::Core::Engine.load_seed if defined?(Spree::Core)
        Spree::Auth::Engine.load_seed if defined?(Spree::Auth)
      RUBY
    end
install_auth_plugin() click to toggle source
# File lib/generators/solidus/install/install_generator.rb, line 130
def install_auth_plugin
  if options[:with_authentication] && (options[:auto_accept] || !no?("
    Solidus has a default authentication extension that uses Devise.
    You can find more info at https://github.com/solidusio/solidus_auth_devise.

    Would you like to install it? (Y/n)"))

    @plugins_to_be_installed << 'solidus_auth_devise'
    @plugin_generators_to_run << 'solidus:auth:install'
  end
end
install_file_attachment() click to toggle source
# File lib/generators/solidus/install/install_generator.rb, line 55
def install_file_attachment
  if options[:active_storage]
    say "Installing Active Storage", :green
    rake 'active_storage:install'
  else
    say "Installing Paperclip", :green
    gsub_file 'config/initializers/spree.rb', "ActiveStorageAttachment", "PaperclipAttachment"
  end
end
install_migrations() click to toggle source
# File lib/generators/solidus/install/install_generator.rb, line 169
def install_migrations
  say_status :copying, "migrations"
  `rake railties:install:migrations`
end
install_payment_method() click to toggle source
# File lib/generators/solidus/install/install_generator.rb, line 142
  def install_payment_method
    name = options[:payment_method]

    unless options[:auto_accept]
      available_names = PAYMENT_METHODS.keys

      name = ask("
You can select a payment method to be included in the installation process.
Please select a payment method name:", limited_to: available_names, default: available_names.first)
    end

    gem_name = PAYMENT_METHODS.fetch(name)

    if gem_name
      @plugins_to_be_installed << gem_name
      @plugin_generators_to_run << "#{gem_name}:install"
    end
  end
install_routes() click to toggle source
# File lib/generators/solidus/install/install_generator.rb, line 225
    def install_routes
      routes_file_path = File.join('config', 'routes.rb')
      unless File.read(routes_file_path).include? CORE_MOUNT_ROUTE
        insert_into_file routes_file_path, after: "Rails.application.routes.draw do\n" do
          <<-RUBY
  # This line mounts Solidus's routes at the root of your application.
  # This means, any requests to URLs such as /products, will go to Spree::ProductsController.
  # If you would like to change where this engine is mounted, simply change the :at option to something different.
  #
  # We ask that you don't use the :as option here, as Solidus relies on it being the default of "spree"
  #{CORE_MOUNT_ROUTE}, at: '/'

          RUBY
        end
      end

      unless options[:quiet]
        puts "*" * 50
        puts "We added the following line to your application's config/routes.rb file:"
        puts " "
        puts "    #{CORE_MOUNT_ROUTE}, at: '/'"
      end
    end
load_sample_data() click to toggle source
# File lib/generators/solidus/install/install_generator.rb, line 216
def load_sample_data
  if @load_sample_data
    say_status :loading, "sample data"
    rake 'spree_sample:load'
  else
    say_status :skipping, "sample data (you can always run rake spree_sample:load)"
  end
end
plugin_install_preparation() click to toggle source
# File lib/generators/solidus/install/install_generator.rb, line 125
def plugin_install_preparation
  @plugins_to_be_installed = []
  @plugin_generators_to_run = []
end
populate_seed_data() click to toggle source
# File lib/generators/solidus/install/install_generator.rb, line 202
def populate_seed_data
  if @load_seed_data
    say_status :loading,  "seed data"
    rake_options = []
    rake_options << "AUTO_ACCEPT=1" if options[:auto_accept]
    rake_options << "ADMIN_EMAIL=#{options[:admin_email]}" if options[:admin_email]
    rake_options << "ADMIN_PASSWORD=#{options[:admin_password]}" if options[:admin_password]

    rake("db:seed #{rake_options.join(' ')}")
  else
    say_status :skipping, "seed data (you can always run rake db:seed)"
  end
end
prepare_options() click to toggle source
# File lib/generators/solidus/install/install_generator.rb, line 40
def prepare_options
  @run_migrations = options[:migrate]
  @load_seed_data = options[:seed]
  @load_sample_data = options[:sample]

  unless @run_migrations
     @load_seed_data = false
     @load_sample_data = false
  end
end
run_bundle_install_if_needed_by_plugins() click to toggle source
# File lib/generators/solidus/install/install_generator.rb, line 179
def run_bundle_install_if_needed_by_plugins
  @plugins_to_be_installed.each do |plugin_name|
    gem plugin_name
  end

  bundle_cleanly{ run "bundle install" } if @plugins_to_be_installed.any?
  run "spring stop" if defined?(Spring)

  @plugin_generators_to_run.each do |plugin_generator_name|
    generate "#{plugin_generator_name} --skip_migrations=true"
  end
end
run_migrations() click to toggle source
# File lib/generators/solidus/install/install_generator.rb, line 192
def run_migrations
  if @run_migrations
    say_status :running, "migrations"

    rake 'db:migrate VERBOSE=false'
  else
    say_status :skipping, "migrations (don't forget to run rake db:migrate)"
  end
end
setup_assets() click to toggle source
# File lib/generators/solidus/install/install_generator.rb, line 80
def setup_assets
  @lib_name = 'spree'

  empty_directory 'app/assets/images'

  %w{javascripts stylesheets images}.each do |path|
    empty_directory "vendor/assets/#{path}/spree/frontend" if defined? Spree::Frontend || Rails.env.test?
    empty_directory "vendor/assets/#{path}/spree/backend" if defined? Spree::Backend || Rails.env.test?
  end

  if defined? Spree::Frontend || Rails.env.test?
    template "vendor/assets/javascripts/spree/frontend/all.js"
    template "vendor/assets/stylesheets/spree/frontend/all.css"
  end

  if defined? Spree::Backend || Rails.env.test?
    template "vendor/assets/javascripts/spree/backend/all.js"
    template "vendor/assets/stylesheets/spree/backend/all.css"
  end
end

Private Instance Methods

bundle_cleanly(&block) click to toggle source
# File lib/generators/solidus/install/install_generator.rb, line 260
def bundle_cleanly(&block)
  Bundler.respond_to?(:with_unbundled_env) ? Bundler.with_unbundled_env(&block) : Bundler.with_clean_env(&block)
end