Sha256: 9d4c2239f24f9c91a66153d6b1d44d1f43ebe37eab15a2418f0feb37508fcfd0

Contents?: true

Size: 1.46 KB

Versions: 2

Compression:

Stored size: 1.46 KB

Contents

# frozen_string_literal: true

require "erb"
require "hanami/cli/generators/app/slice_context"

module Hanami
  module RSpec
    module Generators
      class Slice
        def initialize(fs:, inflector:)
          @fs = fs
          @inflector = inflector
        end

        def call(slice, context: Hanami::CLI::Generators::App::SliceContext.new(inflector, nil, slice, nil))
          fs.write("spec/slices/#{slice}/action_spec.rb", t("action_spec.erb", context))
          # fs.write("spec/slices/#{slice}/view_spec.rb", t("view_spec.erb", context))
          # fs.write("spec/slices/#{slice}/repository_spec.rb", t("repository_spec.erb", context))

          fs.write("spec/slices/#{slice}/actions/.keep", t("keep.erb", context))
          # fs.write("spec/slices/#{slice}/views/.keep", t("keep.erb", context))
          # fs.write("spec/slices/#{slice}/templates/.keep", t("keep.erb", context))
          # fs.write("spec/slices/#{slice}/templates/layouts/.keep", t("keep.erb", context))
          # fs.write("spec/slices/#{slice}/entities/.keep", t("keep.erb", context))
          # fs.write("spec/slices/#{slice}/repositories/.keep", t("keep.erb", context))
        end

        private

        attr_reader :fs

        attr_reader :inflector

        def template(path, context)
          require "erb"

          ERB.new(
            File.read(__dir__ + "/slice/#{path}")
          ).result(context.ctx)
        end

        alias_method :t, :template
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
hanami-rspec-2.0.0.rc1 lib/hanami/rspec/generators/slice.rb
hanami-rspec-3.11.0.beta4 lib/hanami/rspec/generators/slice.rb