Class: HeliosTracker::InstallGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- HeliosTracker::InstallGenerator
- Includes:
- Rails::Generators::Migration
- Defined in:
- lib/generators/helios_tracker/install_generator.rb
Class Method Summary collapse
Instance Method Summary collapse
- #add_helios_tracker_concern_to_application_controller ⇒ Object
- #add_utm_concern_to_application_controller ⇒ Object
- #create_add_hmid_to_visits_migration ⇒ Object
- #create_blocked_emails_migration ⇒ Object
- #create_initializer ⇒ Object
- #install_universal_track_manager ⇒ Object
- #mount_engine_routes ⇒ Object
- #print_post_install ⇒ Object
Class Method Details
.next_migration_number(path) ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/generators/helios_tracker/install_generator.rb', line 16 def self.next_migration_number(path) # Find the highest existing migration number and increment by 1, # avoiding collisions with UTM migrations created in the same second. existing = Dir.glob("#{path}/[0-9]*_*.rb").map { |f| File.basename(f).split("_", 2).first.to_i } candidate = Time.now.utc.strftime("%Y%m%d%H%M%S").to_i [candidate, *existing].max + 1 end |
Instance Method Details
#add_helios_tracker_concern_to_application_controller ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/generators/helios_tracker/install_generator.rb', line 59 def add_helios_tracker_concern_to_application_controller app_controller = "app/controllers/application_controller.rb" if File.exist?(app_controller) content = File.read(app_controller) if content.include?("HeliosTrackerConcern") say "HeliosTrackerConcern already included in ApplicationController", :yellow else inject_into_class app_controller, "ApplicationController", " include HeliosTrackerConcern\n" say "Added HeliosTrackerConcern to ApplicationController", :green end else say "Could not find #{app_controller} — please add `include HeliosTrackerConcern` manually", :red end end |
#add_utm_concern_to_application_controller ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/generators/helios_tracker/install_generator.rb', line 38 def add_utm_concern_to_application_controller if [:skip_utm] say "Skipping UTM concern injection (--skip-utm)", :yellow return end app_controller = "app/controllers/application_controller.rb" if File.exist?(app_controller) content = File.read(app_controller) if content.include?("UniversalTrackManagerConcern") say "UniversalTrackManagerConcern already included in ApplicationController", :yellow else inject_into_class app_controller, "ApplicationController", " include UniversalTrackManagerConcern\n" say "Added UniversalTrackManagerConcern to ApplicationController", :green end else say "Could not find #{app_controller} — please add `include UniversalTrackManagerConcern` manually", :red end end |
#create_add_hmid_to_visits_migration ⇒ Object
75 76 77 78 |
# File 'lib/generators/helios_tracker/install_generator.rb', line 75 def create_add_hmid_to_visits_migration migration_template "add_hmid_to_visits.rb.erb", "db/migrate/add_hmid_to_visits.rb" end |
#create_blocked_emails_migration ⇒ Object
80 81 82 83 |
# File 'lib/generators/helios_tracker/install_generator.rb', line 80 def create_blocked_emails_migration migration_template "create_blocked_emails.rb.erb", "db/migrate/create_blocked_emails.rb" end |
#create_initializer ⇒ Object
85 86 87 88 |
# File 'lib/generators/helios_tracker/install_generator.rb', line 85 def create_initializer @user_class = [:user_class] template "helios_tracker.rb.erb", "config/initializers/helios_tracker.rb" end |
#install_universal_track_manager ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/generators/helios_tracker/install_generator.rb', line 24 def install_universal_track_manager if [:skip_utm] say "Skipping Universal Track Manager installation (--skip-utm)", :yellow return end if File.exist?("config/initializers/universal_track_manager.rb") say "Universal Track Manager initializer already exists, skipping UTM install", :yellow else say "Installing Universal Track Manager...", :green generate "universal_track_manager:install" end end |
#mount_engine_routes ⇒ Object
90 91 92 93 94 95 96 97 98 99 |
# File 'lib/generators/helios_tracker/install_generator.rb', line 90 def mount_engine_routes route_file = "config/routes.rb" content = File.read(route_file) if content.include?("mount HeliosTracker::Engine") say "HeliosTracker engine already mounted in routes", :yellow else route "mount HeliosTracker::Engine, at: '/'" say "Mounted HeliosTracker::Engine at '/' in routes", :green end end |
#print_post_install ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/generators/helios_tracker/install_generator.rb', line 101 def print_post_install say "" say "=" * 60, :green say "Helios Tracker installed successfully!", :green say "=" * 60, :green say "" say "Next steps:", :yellow say " 1. Run `rails db:migrate`" say " 2. Set HELIOS_TRACKER_API_KEY in your environment (.env or production config)" say " 3. Edit config/initializers/helios_tracker.rb to configure your user scope and fields" say " 4. Your API endpoints are now available at:" say " GET /api/all_users.json" say " GET /api/all_visits.json" say " GET /api/blocked_emails.json" say "" end |