Sha256: 5e2a82ba86a03a0ebdc136f3b829e3a8180e272542d4b2bd5e192d558d45fa96

Contents?: true

Size: 1.81 KB

Versions: 4

Compression:

Stored size: 1.81 KB

Contents

# frozen_string_literal: true

require "refinements/arrays"

module Gemsmith
  module Generators
    # Generates Rake support.
    class Rake < Base
      using Refinements::Arrays

      def generate_code_quality_task
        return "" if code_quality_tasks.empty?
        %(\ndesc "Run code quality checks"\ntask code_quality: %i[#{code_quality_tasks}]\n)
      end

      def generate_default_task
        return "" if default_task.empty?
        %(\ntask default: %i[#{default_task}]\n)
      end

      def run
        cli.template "%gem_name%/Rakefile.tt", configuration
        append_code_quality_task
        append_default_task
      end

      private

      def rspec_task
        configuration.dig(:generate, :rspec) ? "spec" : ""
      end

      def bundler_audit_task
        configuration.dig(:generate, :bundler_audit) ? "bundle:audit" : ""
      end

      def git_cop_task
        configuration.dig(:generate, :git_cop) ? "git_cop" : ""
      end

      def reek_task
        configuration.dig(:generate, :reek) ? "reek" : ""
      end

      def rubocop_task
        configuration.dig(:generate, :rubocop) ? "rubocop" : ""
      end

      def code_quality_tasks
        [
          bundler_audit_task,
          git_cop_task,
          reek_task,
          rubocop_task
        ].compress.join " "
      end

      def code_quality_task
        code_quality_tasks.empty? ? "" : "code_quality"
      end

      def default_task
        [code_quality_task, rspec_task].compress.join " "
      end

      def append_code_quality_task
        return if code_quality_task.empty?
        cli.append_to_file "%gem_name%/Rakefile", generate_code_quality_task
      end

      def append_default_task
        return if default_task.empty?
        cli.append_to_file "%gem_name%/Rakefile", generate_default_task
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
gemsmith-11.2.0 lib/gemsmith/generators/rake.rb
gemsmith-11.1.0 lib/gemsmith/generators/rake.rb
gemsmith-11.0.1 lib/gemsmith/generators/rake.rb
gemsmith-11.0.0 lib/gemsmith/generators/rake.rb