Class: ActivityNotification::Generators::ModelsGenerator

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

Overview

Notification generator to create customizable notification model from templates.

Examples:

Run notification generator to create customizable notification model

rails generate activity_notification:models users

Constant Summary collapse

MODELS =
['notification', 'subscription'].freeze

Instance Method Summary collapse

Instance Method Details

#create_modelsObject

Create notification model in application directory



36
37
38
39
40
41
42
43
44
45
# File 'lib/generators/activity_notification/models_generator.rb', line 36

def create_models
  @target_prefix = target.blank? ? '' : (target.camelize + '::')
  models      = options[:models] || MODELS
  model_names = options[:names]  || MODELS
  models.zip(model_names).each do |original_name, new_name|
    @model_name = new_name.camelize
    template "#{original_name}.rb",
             "app/models/#{target}/#{@model_name.underscore}.rb"
  end
end

#show_readmeObject

Shows readme to console



48
49
50
# File 'lib/generators/activity_notification/models_generator.rb', line 48

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