Class: ActivityNotification::Generators::InstallGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/activity_notification/install_generator.rb

Overview

Install generator to copy initializer and locale file to rails application.

Examples:

Run install generator

rails generate activity_notification:install

Instance Method Summary collapse

Instance Method Details

#copy_initializerObject

Copies initializer file in application directory



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/generators/activity_notification/install_generator.rb', line 15

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

#copy_localeObject

Copies locale files in application directory



32
33
34
# File 'lib/generators/activity_notification/install_generator.rb', line 32

def copy_locale
  template "locales/en.yml", "config/locales/activity_notification.en.yml"
end

#show_readmeObject

Shows readme to console



37
38
39
# File 'lib/generators/activity_notification/install_generator.rb', line 37

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