Class: UsageCredits::Generators::InstallGenerator

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.next_migration_number(dir) ⇒ Object



13
14
15
# File 'lib/generators/usage_credits/install_generator.rb', line 13

def self.next_migration_number(dir)
  ActiveRecord::Generators::Base.next_migration_number(dir)
end

Instance Method Details

#create_initializerObject



21
22
23
# File 'lib/generators/usage_credits/install_generator.rb', line 21

def create_initializer
  template "initializer.rb", "config/initializers/usage_credits.rb"
end

#create_migration_fileObject



17
18
19
# File 'lib/generators/usage_credits/install_generator.rb', line 17

def create_migration_file
  migration_template "create_usage_credits_tables.rb.erb", File.join(db_migrate_path, "create_usage_credits_tables.rb")
end

#display_post_install_messageObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/generators/usage_credits/install_generator.rb', line 25

def display_post_install_message
  say "\nšŸŽ‰ The `usage_credits` gem has been successfully installed!", :green
  say "\nTo complete the setup:"

  say "  1. Run 'rails db:migrate' to create the necessary tables."
  say "     āš ļø  You must run migrations before starting your app!", :yellow

  say "  2. Add 'has_credits' to your User model (or any model that should have credits)."

  say "  3. Define the actions that consume credits in config/initializers/usage_credits.rb"
  say "     āž”ļø See README.md for usage examples and detailed configuration options."

  say "  4. šŸ’ø Make sure you have the `pay` gem installed and configured for your chosen payment processor(s) if you want to handle payments and subscriptions (f.ex. for credit refills)"

  say "\nEnjoy your new usage-based credits system! šŸ’³āœØ\n", :green
end