Sha256: f5698efb412e01dc1ce8f7e8c320193ff8f38f5e3d379db3196b6508d47353bb

Contents?: true

Size: 982 Bytes

Versions: 3

Compression:

Stored size: 982 Bytes

Contents

# frozen_string_literal: true

require "bundler"
require "bundler/cli"

module Rubysmith
  module Builders
    # Builds Bundler Gemfile configuration and installs gem dependencies for project skeleton.
    class Bundler
      def self.call realm, builder: Builder
        new(realm, builder: builder).call
      end

      def initialize realm, builder: Builder, runner: ::Bundler::CLI
        @realm = realm
        @builder = builder
        @runner = runner
      end

      def call
        builder.call(realm.with(template_path: "%project_name%/Gemfile.erb"))
               .render
               .replace(/\n\s*group/, "\n\ngroup")
               .replace(/\n\s*gem/, "\n  gem")
               .replace(/\s{4}\n/, "")
               .replace("  end", "end")
               .replace(/\n{1,}\Z/, "\n")
        Dir.chdir(realm.project_root) { runner.start %w[install --quiet] }
        nil
      end

      private

      attr_reader :realm, :builder, :runner
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rubysmith-0.5.0 lib/rubysmith/builders/bundler.rb
rubysmith-0.4.0 lib/rubysmith/builders/bundler.rb
rubysmith-0.3.0 lib/rubysmith/builders/bundler.rb