Class: Upkeep::InstallGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- Upkeep::InstallGenerator
- Includes:
- Rails::Generators::Migration
- Defined in:
- lib/generators/upkeep/install/install_generator.rb
Constant Summary collapse
- SOLID_CABLE_DEVELOPMENT_BLOCK =
<<~YAML development: adapter: solid_cable connects_to: database: writing: cable polling_interval: 0.1.seconds message_retention: 1.day YAML
Class Method Summary collapse
Instance Method Summary collapse
- #configure_development_cable_adapter ⇒ Object
- #create_browser_bootstrap ⇒ Object
- #create_initializer ⇒ Object
- #create_subscription_migration ⇒ Object
- #mount_action_cable ⇒ Object
- #show_identity_setup_guidance ⇒ Object
Class Method Details
.next_migration_number(dirname) ⇒ Object
23 24 25 |
# File 'lib/generators/upkeep/install/install_generator.rb', line 23 def self.next_migration_number(dirname) ActiveRecord::Generators::Base.next_migration_number(dirname) end |
Instance Method Details
#configure_development_cable_adapter ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/generators/upkeep/install/install_generator.rb', line 50 def configure_development_cable_adapter unless solid_cable_in_gemfile? show_solid_cable_guidance return end return unless cable_config_path.exist? content = cable_config_path.read block = development_cable_block(content) return if block&.include?("solid_cable") updated = if block content.sub(block, "#{SOLID_CABLE_DEVELOPMENT_BLOCK}\n") else "#{SOLID_CABLE_DEVELOPMENT_BLOCK}\n#{content}" end File.write(cable_config_path, updated) say "Updated config/cable.yml development to the solid_cable adapter." say "Ensure config/database.yml defines a cable database for development and loads db/cable_schema.rb." end |
#create_browser_bootstrap ⇒ Object
38 39 40 41 42 |
# File 'lib/generators/upkeep/install/install_generator.rb', line 38 def create_browser_bootstrap template "subscription.js", "app/javascript/upkeep/subscription.js" append_application_import pin_action_cable end |
#create_initializer ⇒ Object
34 35 36 |
# File 'lib/generators/upkeep/install/install_generator.rb', line 34 def create_initializer template "upkeep.rb", "config/initializers/upkeep.rb" end |
#create_subscription_migration ⇒ Object
27 28 29 30 31 32 |
# File 'lib/generators/upkeep/install/install_generator.rb', line 27 def create_subscription_migration return if migration_exists?("create_upkeep_subscriptions") @migration_version = ActiveRecord::Migration.current_version migration_template "create_upkeep_subscriptions.rb.erb", "db/migrate/create_upkeep_subscriptions.rb" end |
#mount_action_cable ⇒ Object
44 45 46 47 48 |
# File 'lib/generators/upkeep/install/install_generator.rb', line 44 def mount_action_cable return if routes_path.exist? && routes_path.read.include?("ActionCable.server") route %(mount ActionCable.server => "/cable") end |
#show_identity_setup_guidance ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/generators/upkeep/install/install_generator.rb', line 71 def show_identity_setup_guidance usages = detected_identity_usages return if usages.empty? say "\nIdentity setup required", :yellow say "Upkeep found request-side identity usage:" usages.each { |usage| say " #{usage}" } say "Upkeep does not infer subscriber identity by naming convention." say "Add an explicit Upkeep::Rails.configure identity mapping in config/initializers/upkeep.rb." say "Pages that depend on undeclared non-absent CurrentAttributes or Warden identities are refused for live updates." say "" end |