Sha256: 262d63cb5f5a7dbebca018f3bb9294bb16770bfb7c2f907e93ad52f7f5530d61

Contents?: true

Size: 1.8 KB

Versions: 60

Compression:

Stored size: 1.8 KB

Contents

# typed: false
# frozen_string_literal: true

require "rails/generators"
require_relative "../actions"

module Hephaestus
  module Generators
    class Base < Rails::Generators::Base
      include Hephaestus::Actions
      include ExitOnFailure

      class << self
        def default_source_root
          File.expand_path(File.join("..", "..", "..", "templates"), __dir__)
        end

        def inherited(subclass)
          super

          description_file = File.expand_path(
            File.join(
              default_source_root,
              "descriptions",
              "#{subclass.generator_name}.md",
            ),
          )

          subclass.desc(File.read(description_file))
        rescue Errno::ENOENT # rubocop:disable Lint/SuppressedException
        end
      end

      private

      def app_name
        Rails.app_class.module_parent_name.demodulize.underscore.dasherize
      end

      def short_app_name
        app_name.sub(/plug-/i, "")
      end

      def empty_directory_with_keep_file(destination)
        empty_directory(destination, {})
        keep_file(destination)
      end

      def keep_file(destination)
        create_file(File.join(destination, ".keep"))
      end

      def append_template_to_file(destination, source, *args)
        partial = File.expand_path(find_in_source_paths(source))
        append_to_file(destination, File.read(partial, *args))
      end

      def prepend_template_to_file(destination, source, *args)
        partial = File.expand_path(find_in_source_paths(source))
        prepend_to_file(destination, File.read(partial, *args))
      end

      def inject_template_into_file(destination, source, *args)
        partial = File.expand_path(find_in_source_paths(source))
        inject_into_file(destination, File.read(partial), *args)
      end
    end
  end
end

Version data entries

60 entries across 60 versions & 1 rubygems

Version Path
hephaestus-0.8.12 lib/hephaestus/generators/base.rb
hephaestus-0.8.11 lib/hephaestus/generators/base.rb
hephaestus-0.8.10 lib/hephaestus/generators/base.rb
hephaestus-0.8.9.2 lib/hephaestus/generators/base.rb
hephaestus-0.8.9.1 lib/hephaestus/generators/base.rb
hephaestus-0.8.9 lib/hephaestus/generators/base.rb
hephaestus-0.8.8 lib/hephaestus/generators/base.rb
hephaestus-0.8.7.5 lib/hephaestus/generators/base.rb
hephaestus-0.8.7.4 lib/hephaestus/generators/base.rb
hephaestus-0.8.7.3 lib/hephaestus/generators/base.rb
hephaestus-0.8.7.2 lib/hephaestus/generators/base.rb
hephaestus-0.8.7.1 lib/hephaestus/generators/base.rb
hephaestus-0.8.7 lib/hephaestus/generators/base.rb
hephaestus-0.8.6 lib/hephaestus/generators/base.rb
hephaestus-0.8.5 lib/hephaestus/generators/base.rb
hephaestus-0.8.4.1 lib/hephaestus/generators/base.rb
hephaestus-0.8.4 lib/hephaestus/generators/base.rb
hephaestus-0.8.3.4 lib/hephaestus/generators/base.rb
hephaestus-0.8.3.3 lib/hephaestus/generators/base.rb
hephaestus-0.8.3.2 lib/hephaestus/generators/base.rb