Sha256: decdf910f9b8a2d9105944409247c9813aba205bc944895ebe7411f3e1fedc0d

Contents?: true

Size: 1.23 KB

Versions: 2

Compression:

Stored size: 1.23 KB

Contents

require "dry/web/web_pipe/generate"
require "dry/web/web_pipe/generators/inflections"

module Dry
  module Web
    module WebPipe
      module Generators
        class AbstractGenerator
          attr_reader :target_dir, :options

          def initialize(target_dir, options = {})
            @target_dir = target_dir
            @options = options
            @templates = []
            populate_templates
            @templates.freeze
          end

          def call
            templates.each do |source, target|
              generator.(source, target)
            end
            post_process_callback
          end

          private
          attr_reader :templates

          def add_template(source, target)
            templates << [source, target]
          end

          def generator
            @generator ||= Generate.new(destination, template_scope)
          end

          def post_process_callback; end

          def underscored_project_name
            @underscored_project_name ||= Inflections.underscored_name(target_dir)
          end

          def template_scope
            fail NotImplementedError
          end

          def destination
            fail NotImplementedError
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
dry-web-web_pipe-0.2.0 lib/dry/web/web_pipe/generators/abstract_generator.rb
dry-web-web_pipe-0.1.0 lib/dry/web/web_pipe/generators/abstract_generator.rb