Sha256: d84997b42decd142a56eba549f845dd019c7e4ec32a4e4d11d407ee452972131

Contents?: true

Size: 1.12 KB

Versions: 2

Compression:

Stored size: 1.12 KB

Contents

# frozen_string_literal: true

require 'rails/generators/base'
require 'securerandom'

module Kingsman
  module Generators
    MissingORMError = Class.new(Thor::Error)

    class InstallGenerator < Rails::Generators::Base
      source_root File.expand_path("../../templates", __FILE__)

      desc "Creates a Kingsman initializer and copy locale files to your application."
      class_option :orm, required: true

      def copy_initializer
        unless options[:orm]
          raise MissingORMError, <<-ERROR.strip_heredoc
          An ORM must be set to install Kingsman in your application.

          Be sure to have an ORM like Active Record or Mongoid loaded in your
          app or configure your own at `config/application.rb`.

            config.generators do |g|
              g.orm :your_orm_gem
            end
          ERROR
        end

        template "kingsman.rb", "config/initializers/kingsman.rb"
      end

      def copy_locale
        copy_file "../../../config/locales/en.yml", "config/locales/kingsman.en.yml"
      end

      def show_readme
        readme "README" if behavior == :invoke
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
kingsman-0.1.1 lib/generators/kingsman/install_generator.rb
kingsman-0.1.0 lib/generators/kingsman/install_generator.rb