Skip to content

Commit 8bad850

Browse files
rameerezclaude
andcommitted
Align install generator with api_keys and usage_credits patterns
- Add post-install message with setup instructions - Use same next_migration_number pattern as api_keys gem - Clean up formatting to match conventions Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 9667ef0 commit 8bad850

File tree

1 file changed

+28
-8
lines changed

1 file changed

+28
-8
lines changed
Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,53 @@
11
# frozen_string_literal: true
22

3-
require 'rails/generators/base'
4-
require 'rails/generators/active_record'
3+
require "rails/generators/base"
4+
require "rails/generators/active_record"
55

66
module Footprinted
77
module Generators
88
class InstallGenerator < Rails::Generators::Base
99
include ActiveRecord::Generators::Migration
1010

11-
source_root File.expand_path('templates', __dir__)
11+
source_root File.expand_path("templates", __dir__)
1212

13-
def self.next_migration_number(dir)
14-
ActiveRecord::Generators::Base.next_migration_number(dir)
13+
def self.next_migration_number(dirname)
14+
next_migration_number = current_migration_number(dirname) + 1
15+
ActiveRecord::Migration.next_migration_number(next_migration_number)
1516
end
1617

1718
def create_migration_file
18-
migration_template 'create_footprinted_footprints.rb.erb', File.join(db_migrate_path, "create_footprinted_footprints.rb")
19+
migration_template "create_footprinted_footprints.rb.erb",
20+
File.join(db_migrate_path, "create_footprinted_footprints.rb")
1921
end
2022

2123
def create_initializer
22-
template 'footprinted.rb', 'config/initializers/footprinted.rb'
24+
template "footprinted.rb", "config/initializers/footprinted.rb"
25+
end
26+
27+
def display_post_install_message
28+
say "\n🎉 The `footprinted` gem has been successfully installed!", :green
29+
say "\nTo complete the setup:"
30+
say " 1. Run `rails db:migrate` to create the footprints table."
31+
say " ⚠️ You must run migrations before starting your app!", :yellow
32+
say "\n 2. Add `include Footprinted::Model` to any model you want to track:"
33+
say " class Product < ApplicationRecord"
34+
say " include Footprinted::Model"
35+
say " end"
36+
say "\n 3. Create footprints from your controllers or services:"
37+
say " product.footprints.create!("
38+
say " ip: request.remote_ip,"
39+
say " event_type: 'page_view',"
40+
say " occurred_at: Time.current"
41+
say " )"
42+
say "\nSee the footprinted README for detailed usage and examples.", :cyan
43+
say "Happy tracking! 👣\n", :green
2344
end
2445

2546
private
2647

2748
def migration_version
2849
"[#{ActiveRecord::VERSION::STRING.to_f}]"
2950
end
30-
3151
end
3252
end
3353
end

0 commit comments

Comments
 (0)