Class: ActivityNotification::Generators::ControllersGenerator

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

Overview

Controller generator to create customizable controller files from templates.

Examples:

Run controller generator for users as target

rails generate activity_notification:controllers users

Constant Summary collapse

CONTROLLERS =
['notifications', 'notifications_with_devise', 'notifications_api', 'notifications_api_with_devise',
'subscriptions', 'subscriptions_with_devise', 'subscriptions_api', 'subscriptions_api_with_devise'].freeze

Instance Method Summary collapse

Instance Method Details

#create_controllersObject

Creates controller files in application directory



35
36
37
38
39
40
41
42
# File 'lib/generators/activity_notification/controllers_generator.rb', line 35

def create_controllers
  @target_prefix = target.blank? ? '' : (target.camelize + '::')
  controllers = options[:controllers] || CONTROLLERS
  controllers.each do |name|
    template "#{name}_controller.rb",
             "app/controllers/#{target}/#{name}_controller.rb"
  end
end

#show_readmeObject

Shows readme to console



45
46
47
# File 'lib/generators/activity_notification/controllers_generator.rb', line 45

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