Sha256: 9cfe3317db6c084de661db062d26c50f3dda6a6ed13f5881f266e524eda172d3

Contents?: true

Size: 1.41 KB

Versions: 26

Compression:

Stored size: 1.41 KB

Contents

require 'rails/generators/base'

module ActivityNotification
  module Generators #:nodoc:
    # Install generator to copy initializer and locale file to rails application.
    # @example Run install generator
    #   rails generate activity_notification:install
    class InstallGenerator < Rails::Generators::Base
      source_root File.expand_path("../../templates", __FILE__)

      desc "Creates a ActivityNotification initializer and copy locale files to your application."
      class_option :orm

      # Copies initializer file in application directory
      def copy_initializer
        unless [:active_record, :mongoid].include?(options[:orm])
          raise TypeError, <<-ERROR.strip_heredoc
          Currently ActivityNotification is only supported with ActiveRecord or Mongoid ORM.

          Be sure to have an ActiveRecord or MongoidORM loaded in your app or configure your own at `config/application.rb`.

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

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

      # Copies locale files in application directory
      def copy_locale
        template "locales/en.yml", "config/locales/activity_notification.en.yml"
      end

      # Shows readme to console
      def show_readme
        readme "README" if behavior == :invoke
      end

    end
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
activity_notification-1.4.4 lib/generators/activity_notification/install_generator.rb
activity_notification-1.4.3 lib/generators/activity_notification/install_generator.rb
activity_notification-1.4.2 lib/generators/activity_notification/install_generator.rb
activity_notification-1.4.1 lib/generators/activity_notification/install_generator.rb
activity_notification-1.4.0 lib/generators/activity_notification/install_generator.rb
activity_notification-1.3.0 lib/generators/activity_notification/install_generator.rb