Sha256: e3d90d46028e3d709789a00bb569aebc29bbcf89df764af53e8d2fe44766452b

Contents?: true

Size: 1.16 KB

Versions: 11

Compression:

Stored size: 1.16 KB

Contents

# frozen_string_literal: true

require "refinements/struct"

module Hanamismith
  module Builders
    # Builds project skeleton console for object inspection and exploration.
    class Console < Rubysmith::Builders::Console
      using Refinements::Struct

      def call
        return configuration unless configuration.build_console

        super
        builder.call(configuration.merge(template_path: "%project_name%/bin/console.erb"))
               .replace(/require Bundler.root.+/, %(require "hanami/prepare"))

        add_irb_autocomplete

        configuration
      end

      private

      def add_irb_autocomplete
        with_template.insert_before "IRB.start",
                                    <<~CODE
                                      unless Hanami.env? :development, :test
                                        ENV["IRB_USE_AUTOCOMPLETE"] ||= "false"
                                        puts "IRB autocomplete disabled."
                                      end

                                    CODE
      end

      def with_template
        builder.call configuration.merge(template_path: "%project_name%/bin/console.erb")
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
hanamismith-0.34.0 lib/hanamismith/builders/console.rb
hanamismith-0.33.0 lib/hanamismith/builders/console.rb
hanamismith-0.32.0 lib/hanamismith/builders/console.rb
hanamismith-0.31.0 lib/hanamismith/builders/console.rb
hanamismith-0.30.0 lib/hanamismith/builders/console.rb
hanamismith-0.29.0 lib/hanamismith/builders/console.rb
hanamismith-0.28.1 lib/hanamismith/builders/console.rb
hanamismith-0.28.0 lib/hanamismith/builders/console.rb
hanamismith-0.27.0 lib/hanamismith/builders/console.rb
hanamismith-0.26.0 lib/hanamismith/builders/console.rb
hanamismith-0.25.0 lib/hanamismith/builders/console.rb