Sha256: 4a061702177981c49b534653202aa580d06ab13f7f9bfb29ccfa8cb58325e3d0

Contents?: true

Size: 1.97 KB

Versions: 3

Compression:

Stored size: 1.97 KB

Contents

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

3 entries across 3 versions & 1 rubygems

Version Path
gemsmith-6.2.0 lib/gemsmith/skeletons/rails_skeleton.rb
gemsmith-6.1.0 lib/gemsmith/skeletons/rails_skeleton.rb
gemsmith-6.0.0 lib/gemsmith/skeletons/rails_skeleton.rb