Class: LlmCostTracker::Generators::InstallGenerator

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

Instance Method Summary collapse

Instance Method Details

#create_initializerObject



27
28
29
30
31
32
# File 'lib/llm_cost_tracker/generators/llm_cost_tracker/install_generator.rb', line 27

def create_initializer
  destination = "config/initializers/llm_cost_tracker.rb"
  return if File.exist?(File.join(destination_root, destination))

  template("initializer.rb.erb", destination)
end

#create_migration_fileObject



20
21
22
23
24
25
# File 'lib/llm_cost_tracker/generators/llm_cost_tracker/install_generator.rb', line 20

def create_migration_file
  migration_template(
    "create_llm_cost_tracker_calls.rb.erb",
    "db/migrate/create_llm_cost_tracker_calls.rb"
  )
end

#create_prices_fileObject



34
35
36
37
38
39
# File 'lib/llm_cost_tracker/generators/llm_cost_tracker/install_generator.rb', line 34

def create_prices_file
  return unless options[:prices]

  require_relative "prices_generator"
  invoke LlmCostTracker::Generators::PricesGenerator
end

#mount_engineObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/llm_cost_tracker/generators/llm_cost_tracker/install_generator.rb', line 41

def mount_engine
  return unless options[:dashboard]

  say(<<~MSG, :yellow)
    The LLM Cost Tracker dashboard ships without authentication.
    Mount it in config/routes.rb behind your app's admin auth, e.g.:

      authenticate :admin do
        mount LlmCostTracker::Engine => "/llm-costs"
      end

    The generator does NOT add a route automatically — leaving the dashboard
    unauthenticated would expose spend, tags, and provider IDs to anyone.
  MSG
end