Class: NotifyWith::InstallGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Includes:
Rails::Generators::Migration
Defined in:
lib/generators/notify_with/install/install_generator.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.next_migration_number(path) ⇒ Object



5
6
7
8
9
10
11
12
# File 'lib/generators/notify_with/install/install_generator.rb', line 5

def self.next_migration_number path
  unless @prev_migration_nr
  @prev_migration_nr = Time.now.utc.strftime("%Y%m%d%H%M%S").to_i
  else
  @prev_migration_nr += 1
  end
  @prev_migration_nr.to_s
end

Instance Method Details

#add_notifications_routeObject



39
40
41
42
43
44
45
46
47
48
# File 'lib/generators/notify_with/install/install_generator.rb', line 39

def add_notifications_route
  route \
<<-CODE
namespace :api, defaults: { format: :json } do
  resources :notifications, only: [:index, :show, :update] do
    match :update_all, path: '/', via: [:put, :patch], on: :collection
  end
end
CODE
end

#add_subject_localeObject



54
55
56
57
58
59
60
61
# File 'lib/generators/notify_with/install/install_generator.rb', line 54

def add_subject_locale
  append_file "config/locales/#{I18n.locale.to_s}.yml" do
<<-CODE
notifications_mailer:
  send_mail_by:
CODE
  end
end

#copy_api_notifications_controllerObject



30
31
32
# File 'lib/generators/notify_with/install/install_generator.rb', line 30

def copy_api_notifications_controller
  template "notifications_controller.rb", "app/controllers/api/notifications_controller.rb"
end

#copy_api_notifications_viewsObject



34
35
36
37
# File 'lib/generators/notify_with/install/install_generator.rb', line 34

def copy_api_notifications_views
  template "index.json.jbuilder", "app/views/api/notifications/index.json.jbuilder"
  template "show.json.jbuilder", "app/views/api/notifications/show.json.jbuilder"
end

#copy_initializerObject



50
51
52
# File 'lib/generators/notify_with/install/install_generator.rb', line 50

def copy_initializer
  template "notify_with.rb", "config/initializers/notify_with.rb"
end

#copy_notification_migrationObject



14
15
16
# File 'lib/generators/notify_with/install/install_generator.rb', line 14

def copy_notification_migration
  migration_template "create_notification.rb", "db/migrate/create_notification.rb"
end

#copy_notification_modelObject



18
19
20
# File 'lib/generators/notify_with/install/install_generator.rb', line 18

def copy_notification_model
  template "notification.rb", "app/models/notification.rb"
end

#copy_notification_type_modelObject



22
23
24
# File 'lib/generators/notify_with/install/install_generator.rb', line 22

def copy_notification_type_model
  template "notification_type.rb", "app/models/notification_type.rb"
end

#copy_notifications_mailerObject



26
27
28
# File 'lib/generators/notify_with/install/install_generator.rb', line 26

def copy_notifications_mailer
  template "notifications_mailer.rb", "app/mailers/notifications_mailer.rb"
end