Sha256: cd1312800fd2802d5076b39681c22f43337f626503cecf276035d53bb8bcb353

Contents?: true

Size: 855 Bytes

Versions: 3

Compression:

Stored size: 855 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{2,}/, "\"\n")
               .replace(/\n\s*gem/, "\n  gem")
        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.2.0 lib/rubysmith/builders/bundler.rb
rubysmith-0.1.1 lib/rubysmith/builders/bundler.rb
rubysmith-0.1.0 lib/rubysmith/builders/bundler.rb