Sha256: fec93140b140d7677b61aba91c91b4bc0c628d1d085c79111d39357e8273f19e

Contents?: true

Size: 1 KB

Versions: 3

Compression:

Stored size: 1 KB

Contents

# frozen_string_literal: true

require "rubocop"
require "stringio"

module Rubysmith
  module Builders
    # Builds project skeleton Rubocop code quality support.
    class Rubocop
      def self.call realm, builder: Builder
        new(realm, builder: builder).call
      end

      def initialize realm, builder: Builder, runner: RuboCop::CLI.new
        @realm = realm
        @builder = builder
        @runner = runner
      end

      def call
        return unless realm.build_rubocop

        builder.call(realm.with(template_path: "%project_name%/bin/rubocop.erb"))
               .render
               .permit 0o755

        builder.call(realm.with(template_path: "%project_name%/.rubocop.yml.erb")).render
        auto_correct
      end

      private

      attr_reader :realm, :builder, :runner

      def auto_correct
        backup = $stdout
        $stdout = StringIO.new
        runner.run ["--auto-correct", "--format", "quiet", realm.project_root.to_s]
        $stdout = backup
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rubysmith-0.2.0 lib/rubysmith/builders/rubocop.rb
rubysmith-0.1.1 lib/rubysmith/builders/rubocop.rb
rubysmith-0.1.0 lib/rubysmith/builders/rubocop.rb