Sha256: 0559b798d7b6b1a438b392467ac193865cb18941314348eb2179e5f754171d04

Contents?: true

Size: 1.15 KB

Versions: 8

Compression:

Stored size: 1.15 KB

Contents

# frozen_string_literal: true

require "refinements/struct"

module Rubysmith
  module Builders
    # Builds project skeleton Rake support.
    class Rake
      using Refinements::Struct

      def self.call(...) = new(...).call

      def initialize configuration, builder: Builder
        @configuration = configuration
        @builder = builder
      end

      def call
        return configuration unless configuration.build_rake

        add_binstub
        add_configuration
        configuration
      end

      private

      attr_reader :configuration, :builder

      def add_binstub
        builder.call(configuration.merge(template_path: "%project_name%/bin/rake.erb"))
               .render
               .permit 0o755
      end

      def add_configuration
        builder.call(configuration.merge(template_path: "%project_name%/Rakefile.erb"))
               .render
               .replace(/\[\s+/, "[")
               .replace(/\s+\]/, "]")
               .replace("  ", "")
               .replace("task.options", "  task.options")
               .replace(/\n+(?=require)/, "\n")
               .replace(/\n{2,}/, "\n\n")
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
rubysmith-6.6.0 lib/rubysmith/builders/rake.rb
rubysmith-6.5.0 lib/rubysmith/builders/rake.rb
rubysmith-6.4.0 lib/rubysmith/builders/rake.rb
rubysmith-6.3.0 lib/rubysmith/builders/rake.rb
rubysmith-6.2.1 lib/rubysmith/builders/rake.rb
rubysmith-6.2.0 lib/rubysmith/builders/rake.rb
rubysmith-6.1.0 lib/rubysmith/builders/rake.rb
rubysmith-6.0.0 lib/rubysmith/builders/rake.rb