Sha256: 16a9b3b5f6ae045ed392904970128527401b800e54c1ebbdc6ea6d509d35a1af

Contents?: true

Size: 1.79 KB

Versions: 1

Compression:

Stored size: 1.79 KB

Contents

module Gemsmith
  module Skeletons
    # Configures Ruby on Rails support.
    class RailsSkeleton < BaseSkeleton
      def enabled?
        cli.template_options.key?(:rails) && cli.template_options[:rails]
      end

      def create_engine
        cli.template "#{lib_root}/%gem_name%/engine.rb.tt", cli.template_options

        gem_name = cli.template_options.fetch :gem_name
        system "rails plugin new --skip #{gem_name} #{engine_options}"

        cli.remove_file "#{gem_name}/app/helpers/#{gem_name}/application_helper.rb", cli.template_options
        cli.remove_file "#{gem_name}/lib/#{gem_name}/version.rb", cli.template_options
        cli.remove_file "#{gem_name}/MIT-LICENSE", cli.template_options
        cli.remove_file "#{gem_name}/README.rdoc", cli.template_options
      end

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

      def create_travis_gemfiles
        return unless cli.template_options[:travis]
        cli.template "%gem_name%/gemfiles/rails-4.1.x.gemfile.tt", cli.template_options
      end

      def create
        return unless enabled?

        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

1 entries across 1 versions & 1 rubygems

Version Path
gemsmith-5.4.0 lib/gemsmith/skeletons/rails_skeleton.rb