Sha256: 9ad53d3dc85e5ea34ce50d108fab867235a4b6528d96550f1737bc527fede5d7

Contents?: true

Size: 1.09 KB

Versions: 17

Compression:

Stored size: 1.09 KB

Contents

# frozen_string_literal: true

require "refinements/strings"
require "refinements/structs"

module Rubysmith
  module Builders
    # Builds project skeleton core structure and minimum file support.
    class Core
      using Refinements::Strings
      using Refinements::Structs

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

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

      def call
        builder.call(configuration.merge(template_path: "%project_name%/lib/%project_path%.rb.erb"))
               .render
               .replace("  require", "require")
               .replace(/    (?=(Zeit|loader|end))/, "")
               .replace("\n  \n", "\n\n")
               .insert_before("module #{module_name}", "#{indentation}# Main namespace.\n")
               .replace("end\n  end", "    end\n  end")

        configuration
      end

      private

      def indentation = "".indent configuration.project_levels

      def module_name = configuration.project_class

      attr_reader :configuration, :builder
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
rubysmith-4.2.0 lib/rubysmith/builders/core.rb
rubysmith-4.1.0 lib/rubysmith/builders/core.rb
rubysmith-4.0.1 lib/rubysmith/builders/core.rb
rubysmith-4.0.0 lib/rubysmith/builders/core.rb
rubysmith-3.8.0 lib/rubysmith/builders/core.rb
rubysmith-3.7.0 lib/rubysmith/builders/core.rb
rubysmith-3.6.0 lib/rubysmith/builders/core.rb
rubysmith-3.5.0 lib/rubysmith/builders/core.rb
rubysmith-3.4.0 lib/rubysmith/builders/core.rb
rubysmith-3.3.0 lib/rubysmith/builders/core.rb
rubysmith-3.2.0 lib/rubysmith/builders/core.rb
rubysmith-3.1.0 lib/rubysmith/builders/core.rb
rubysmith-3.0.1 lib/rubysmith/builders/core.rb
rubysmith-3.0.0 lib/rubysmith/builders/core.rb
rubysmith-2.0.2 lib/rubysmith/builders/core.rb
rubysmith-2.0.1 lib/rubysmith/builders/core.rb
rubysmith-2.0.0 lib/rubysmith/builders/core.rb