Sha256: 019c68a4a60d79919e33c47e6321b403970540390265c4a78ad867c7cb9b3512

Contents?: true

Size: 1.17 KB

Versions: 6

Compression:

Stored size: 1.17 KB

Contents

# frozen_string_literal: true

require "refinements/structs"

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

      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

6 entries across 6 versions & 1 rubygems

Version Path
hanamismith-0.24.0 lib/hanamismith/builders/console.rb
hanamismith-0.23.0 lib/hanamismith/builders/console.rb
hanamismith-0.22.1 lib/hanamismith/builders/console.rb
hanamismith-0.22.0 lib/hanamismith/builders/console.rb
hanamismith-0.21.0 lib/hanamismith/builders/console.rb
hanamismith-0.20.0 lib/hanamismith/builders/console.rb