Sha256: 5c90da31ee987175f6581f6e9c400c74ffe1e3b1292825b4ad2a7973228b52d1

Contents?: true

Size: 2 KB

Versions: 8

Compression:

Stored size: 2 KB

Contents

# frozen_string_literal: true

module Gemsmith
  module Skeletons
    # Configures Ruby on Rails support.
    class RailsSkeleton < BaseSkeleton
      def rails?
        cli.run "command -v rails > /dev/null"
      end

      def install_rails
        return if rails?
        return unless cli.yes?("Ruby on Rails is not installed. Would you like to install it (y/n)?")
        cli.run "gem install rails"
      end

      def create_engine
        gem_name = configuration.gem_name

        cli.template "#{lib_root}/%gem_name%/engine.rb.tt", configuration.to_h
        cli.run "rails plugin new --skip #{gem_name} #{engine_options}"
        cli.remove_file "#{gem_name}/app/helpers/#{gem_name}/application_helper.rb", configuration.to_h
        cli.remove_file "#{gem_name}/lib/#{gem_name}/version.rb", configuration.to_h
        cli.remove_file "#{gem_name}/MIT-LICENSE", configuration.to_h
        cli.remove_file "#{gem_name}/README.rdoc", configuration.to_h
      end

      def create_generator_files
        cli.empty_directory "#{generator_root}/templates"
        cli.template "#{generator_root}/install/install_generator.rb.tt", configuration.to_h
        cli.template "#{generator_root}/install/USAGE.tt", configuration.to_h
        cli.template "#{generator_root}/upgrade/upgrade_generator.rb.tt", configuration.to_h
        cli.template "#{generator_root}/upgrade/USAGE.tt", configuration.to_h
      end

      def create_travis_gemfiles
        return unless configuration.create_travis?
        cli.template "%gem_name%/gemfiles/rails-%rails_version%.x.gemfile.tt", configuration.to_h
      end

      def create
        return unless configuration.create_rails?

        install_rails
        create_engine
        create_generator_files
        create_travis_gemfiles
      end

      private

      def engine_options
        "--skip-bundle --skip-test-unit --skip-keeps --skip-git --mountable --dummy-path=spec/dummy"
      end

      def generator_root
        "#{lib_root}/generators/%gem_name%"
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
gemsmith-7.7.0 lib/gemsmith/skeletons/rails_skeleton.rb
gemsmith-7.6.0 lib/gemsmith/skeletons/rails_skeleton.rb
gemsmith-7.5.0 lib/gemsmith/skeletons/rails_skeleton.rb
gemsmith-7.4.0 lib/gemsmith/skeletons/rails_skeleton.rb
gemsmith-7.3.0 lib/gemsmith/skeletons/rails_skeleton.rb
gemsmith-7.2.0 lib/gemsmith/skeletons/rails_skeleton.rb
gemsmith-7.1.0 lib/gemsmith/skeletons/rails_skeleton.rb
gemsmith-7.0.0 lib/gemsmith/skeletons/rails_skeleton.rb