Class: Tng::Services::Installer

Inherits:
Object
  • Object
show all
Defined in:
lib/tng/services/installer.rb

Class Method Summary collapse

Class Method Details

.configuration_template(rails: false) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/tng/services/installer.rb', line 8

def self.configuration_template(rails: false)
  header = if rails
             "return unless Rails.env.development?"
           else
             "if defined?(Rails) && Rails.respond_to?(:env)\n  return unless Rails.env.development?\nend"
           end

  <<~RUBY
    # frozen_string_literal: true

    #{header}

    Tng.configure do |config|
      # Get your API key from https://app.tng.sh/
      config.api_key = ENV["TNG_API_KEY"]
      config.base_url = ENV["API_BASE_URI"] || "https://app.tng.sh/"

      # Test Helper File (optional - auto-detected if not set)
      # Uncomment to override auto-detection with a custom path
      # Default auto-detection checks: spec/rails_helper.rb, spec/spec_helper.rb, test/test_helper.rb
      # config.test_helper_path = "spec/rails_helper.rb"

      # Ignore paths (relative to project root)
      # config.ignore_files = []
      # config.ignore_folders = []

      # Authentication Configuration
      # Set to false if your application does not require authentication
      # config.authentication_enabled = true

      # ⚠️  IMPORTANT: AUTHENTICATION CONFIGURATION REQUIRED ⚠️
      # You MUST configure your authentication methods below for TNG to work properly.
      # Uncomment and modify the authentication_methods configuration:

      # Authentication Methods (multiple methods supported)
      # Supported authentication types: session, devise, jwt, token_auth, basic_auth, oauth, headers, custom, nil
      # EXAMPLE: Uncomment and modify these examples to match your app's authentication:

      # config.authentication_methods = [
      #   {
      #     method: "authenticate_user_via_session!",
      #     file_location: "app/controllers/application_controller.rb",
      #     auth_type: "session"
      #   },
      #   {
      #     method: "authenticate_user_via_api_key!",
      #     file_location: "app/controllers/application_controller.rb",
      #     auth_type: "headers"
      #   }
      # ]
      # ⚠️  Remember to configure your authentication methods above! ⚠️
    end
  RUBY
end

.install(project_root:, rails_project:, force: false) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/tng/services/installer.rb', line 63

def self.install(project_root:, rails_project:, force: false)
  target = if rails_project
             File.join(project_root, "config", "initializers", "tng.rb")
           else
             File.join(project_root, "tng.rb")
           end

  if File.exist?(target)
    return [false, target] unless force
  end

  dir = File.dirname(target)
  FileUtils.mkdir_p(dir) unless Dir.exist?(dir)
  File.write(target, configuration_template(rails: rails_project))

  [true, target]
end