Class: Develoz::Generators::PushGenerator
- Inherits:
-
Base
- Object
- Rails::Generators::Base
- Base
- Develoz::Generators::PushGenerator
show all
- Defined in:
- lib/generators/develoz/push/push_generator.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Base
#add_gem, #app_class, #app_name, #append_env, #apply_template, #ensure_gitignore, #inject_once, #insert_route, #migration_exists?, next_migration_timestamp
Class Method Details
.source_root ⇒ Object
10
11
12
|
# File 'lib/generators/develoz/push/push_generator.rb', line 10
def self.source_root
File.expand_path("templates", __dir__)
end
|
Instance Method Details
#add_web_push_gem ⇒ Object
23
24
25
|
# File 'lib/generators/develoz/push/push_generator.rb', line 23
def add_web_push_gem
add_gem "web-push"
end
|
#append_vapid_env ⇒ Object
54
55
56
57
58
|
# File 'lib/generators/develoz/push/push_generator.rb', line 54
def append_vapid_env
append_env "VAPID_PUBLIC_KEY", ""
append_env "VAPID_PRIVATE_KEY", ""
append_env "VAPID_SUBJECT", "mailto:noreply@example.com"
end
|
#create_push_notification_service ⇒ Object
39
40
41
42
|
# File 'lib/generators/develoz/push/push_generator.rb', line 39
def create_push_notification_service
template "app/services/push_notification_service.rb.tt",
"app/services/push_notification_service.rb"
end
|
#create_push_subscription_migration ⇒ Object
32
33
34
35
36
37
|
# File 'lib/generators/develoz/push/push_generator.rb', line 32
def create_push_subscription_migration
return if migration_exists?("create_push_subscriptions")
template "db/migrate/create_push_subscriptions.rb.tt",
"db/migrate/#{next_migration_timestamp}_create_push_subscriptions.rb"
end
|
#create_push_subscription_model ⇒ Object
27
28
29
30
|
# File 'lib/generators/develoz/push/push_generator.rb', line 27
def create_push_subscription_model
template "app/models/push_subscription.rb.tt",
"app/models/push_subscription.rb"
end
|
#create_service_worker_push_handlers ⇒ Object
44
45
46
47
|
# File 'lib/generators/develoz/push/push_generator.rb', line 44
def create_service_worker_push_handlers
template "app/views/pwa/sw_push_handlers.js.tt",
"app/views/pwa/sw_push_handlers.js"
end
|
#create_subscription_js ⇒ Object
49
50
51
52
|
# File 'lib/generators/develoz/push/push_generator.rb', line 49
def create_subscription_js
template "app/javascript/pwa/subscription.js.tt",
"app/javascript/pwa/subscription.js"
end
|
#ensure_pwa_prerequisite ⇒ Object
14
15
16
17
18
19
20
21
|
# File 'lib/generators/develoz/push/push_generator.rb', line 14
def ensure_pwa_prerequisite
return if options[:pwa]
say "develoz:push requires --pwa. Enabling PWA automatically.", :yellow
require "generators/develoz/pwa/pwa_generator"
pwa = PwaGenerator.new([], {}, destination_root: destination_root)
PwaGenerator.public_instance_methods(false).each { |m| pwa.public_send(m) }
end
|