Class: RailsAiBridge::Config::Introspection

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_ai_bridge/config/introspection.rb

Overview

Holds introspector selection, exclusion rules, and caching settings.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeIntrospection

Initializes Introspection configuration with sensible defaults.

Attribute Default
+introspectors+ +Configuration::PRESETS[:standard].dup+
+preset+ +:standard+
+excluded_paths+ +%w[node_modules tmp log vendor .git]+
+excluded_models+ common Rails/ActiveStorage/Action* class names
+core_models+ +[]+
+excluded_tables+ +[]+
+disabled_introspection_categories+ +[]+
+cache_ttl+ +30+ (seconds)
+expose_credentials_key_names+ +false+
+additional_introspectors+ +{}+
+search_code_allowed_file_types+ +[]+
+search_code_pattern_max_bytes+ +2048+
+search_code_timeout_seconds+ +5.0+
+snapshot_ttl+ +5+ (seconds)
+cache_warm_on_boot+ +false+
+parallel_introspection+ +false+
+parallel_pool_size+ +4+ (threads)
+parallel_timeout_seconds+ +10+ (seconds per-future and pool shutdown)


97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/rails_ai_bridge/config/introspection.rb', line 97

def initialize
  @introspectors      = Configuration::PRESETS[:standard].dup
  @preset             = :standard
  @excluded_paths     = %w[node_modules tmp log vendor .git]
  @excluded_models    = %w[
    ApplicationRecord
    ActiveStorage::Blob ActiveStorage::Attachment ActiveStorage::VariantRecord
    ActionText::RichText ActionText::EncryptedRichText
    ActionMailbox::InboundEmail ActionMailbox::Record
  ]
  @core_models                       = []
  @excluded_tables                   = []
  @disabled_introspection_categories = []
  @cache_ttl                         = 30
  @expose_credentials_key_names      = false
  @additional_introspectors          = {}
  @search_code_allowed_file_types    = []
  @search_code_pattern_max_bytes     = 2048
  @search_code_timeout_seconds       = 5.0
  @snapshot_ttl                      = 5
  @cache_warm_on_boot                = false
  @parallel_introspection            = false
  @parallel_pool_size                = 4
  @parallel_timeout_seconds          = 10
end

Instance Attribute Details

#additional_introspectorsHash{Symbol => Class}

Returns additional custom introspector classes.

Returns:

  • (Hash{Symbol => Class})

    additional custom introspector classes



43
44
45
# File 'lib/rails_ai_bridge/config/introspection.rb', line 43

def additional_introspectors
  @additional_introspectors
end

#cache_ttlInteger

Returns TTL in seconds for cached introspection results.

Returns:

  • (Integer)

    TTL in seconds for cached introspection results



37
38
39
# File 'lib/rails_ai_bridge/config/introspection.rb', line 37

def cache_ttl
  @cache_ttl
end

#cache_warm_on_bootBoolean

Returns whether to pre-populate the introspection cache on Rails boot.

Returns:

  • (Boolean)

    whether to pre-populate the introspection cache on Rails boot



58
59
60
# File 'lib/rails_ai_bridge/config/introspection.rb', line 58

def cache_warm_on_boot
  @cache_warm_on_boot
end

#core_modelsArray<String>

Returns model class names tagged as +core_entity+ in semantic classification (AI focus).

Returns:

  • (Array<String>)

    model class names tagged as +core_entity+ in semantic classification (AI focus)



28
29
30
# File 'lib/rails_ai_bridge/config/introspection.rb', line 28

def core_models
  @core_models
end

#disabled_introspection_categoriesArray<Symbol>

Returns product-level category keys that subtract introspectors at runtime.

Returns:

  • (Array<Symbol>)

    product-level category keys that subtract introspectors at runtime



34
35
36
# File 'lib/rails_ai_bridge/config/introspection.rb', line 34

def disabled_introspection_categories
  @disabled_introspection_categories
end

#excluded_modelsArray<String>

Returns model class names excluded from introspection.

Returns:

  • (Array<String>)

    model class names excluded from introspection



25
26
27
# File 'lib/rails_ai_bridge/config/introspection.rb', line 25

def excluded_models
  @excluded_models
end

#excluded_pathsArray<String>

Returns directory names excluded from code search.

Returns:

  • (Array<String>)

    directory names excluded from code search



22
23
24
# File 'lib/rails_ai_bridge/config/introspection.rb', line 22

def excluded_paths
  @excluded_paths
end

#excluded_tablesArray<String>

Returns table names/patterns excluded from schema introspection.

Returns:

  • (Array<String>)

    table names/patterns excluded from schema introspection



31
32
33
# File 'lib/rails_ai_bridge/config/introspection.rb', line 31

def excluded_tables
  @excluded_tables
end

#expose_credentials_key_namesBoolean

Returns include credential key names in config introspection output.

Returns:

  • (Boolean)

    include credential key names in config introspection output



40
41
42
# File 'lib/rails_ai_bridge/config/introspection.rb', line 40

def expose_credentials_key_names
  @expose_credentials_key_names
end

#introspectorsArray<Symbol>

Returns active introspector keys.

Returns:

  • (Array<Symbol>)

    active introspector keys



8
9
10
# File 'lib/rails_ai_bridge/config/introspection.rb', line 8

def introspectors
  @introspectors
end

#parallel_introspectionBoolean

Returns whether to run introspectors concurrently (requires concurrent-ruby).

Returns:

  • (Boolean)

    whether to run introspectors concurrently (requires concurrent-ruby)



61
62
63
# File 'lib/rails_ai_bridge/config/introspection.rb', line 61

def parallel_introspection
  @parallel_introspection
end

#parallel_pool_sizeInteger

Returns maximum number of threads in the parallel execution pool. Capped at the number of introspectors so no idle threads are created. Default is +4+. Only relevant when #parallel_introspection is +true+.

Returns:

  • (Integer)

    maximum number of threads in the parallel execution pool. Capped at the number of introspectors so no idle threads are created. Default is +4+. Only relevant when #parallel_introspection is +true+.



66
67
68
# File 'lib/rails_ai_bridge/config/introspection.rb', line 66

def parallel_pool_size
  @parallel_pool_size
end

#parallel_timeout_secondsInteger

Returns seconds to wait for each introspector future and for the thread pool to shut down cleanly. Introspectors that exceed this budget have their result replaced with +{ error: "timed out after Ns" }+. Default is +10+. Only relevant when #parallel_introspection is +true+.

Returns:

  • (Integer)

    seconds to wait for each introspector future and for the thread pool to shut down cleanly. Introspectors that exceed this budget have their result replaced with +{ error: "timed out after Ns" }+. Default is +10+. Only relevant when #parallel_introspection is +true+.



72
73
74
# File 'lib/rails_ai_bridge/config/introspection.rb', line 72

def parallel_timeout_seconds
  @parallel_timeout_seconds
end

#presetSymbol?

Returns the active preset name, or +nil+ if introspectors were modified directly.

Returns:

  • (Symbol, nil)

    The preset name, or nil for modified configurations



138
139
140
# File 'lib/rails_ai_bridge/config/introspection.rb', line 138

def preset
  @preset
end

#search_code_allowed_file_typesArray<String>

Returns extra file extensions allowed for rails_search_code.

Returns:

  • (Array<String>)

    extra file extensions allowed for rails_search_code



46
47
48
# File 'lib/rails_ai_bridge/config/introspection.rb', line 46

def search_code_allowed_file_types
  @search_code_allowed_file_types
end

#search_code_pattern_max_bytesInteger

Returns maximum +pattern+ size in bytes for Tools::SearchCode (ReDoS / abuse guard).

Returns:

  • (Integer)

    maximum +pattern+ size in bytes for Tools::SearchCode (ReDoS / abuse guard)



49
50
51
# File 'lib/rails_ai_bridge/config/introspection.rb', line 49

def search_code_pattern_max_bytes
  @search_code_pattern_max_bytes
end

#search_code_timeout_secondsFloat

Returns seconds before Tools::SearchCode aborts (+0+ disables the timeout).

Returns:



52
53
54
# File 'lib/rails_ai_bridge/config/introspection.rb', line 52

def search_code_timeout_seconds
  @search_code_timeout_seconds
end

#snapshot_ttlInteger

Returns TTL in seconds for fingerprint snapshot caching (avoids redundant filesystem walks).

Returns:

  • (Integer)

    TTL in seconds for fingerprint snapshot caching (avoids redundant filesystem walks)



55
56
57
# File 'lib/rails_ai_bridge/config/introspection.rb', line 55

def snapshot_ttl
  @snapshot_ttl
end

Instance Method Details

#effective_introspectorsArray<Symbol>

Introspectors after removing those disabled by #disabled_introspection_categories.

Returns:

  • (Array<Symbol>)


143
144
145
146
147
148
# File 'lib/rails_ai_bridge/config/introspection.rb', line 143

def effective_introspectors
  disabled = @disabled_introspection_categories.flat_map do |c|
    Configuration::INTROSPECTION_CATEGORY_INTROSPECTORS[c.to_sym] || []
  end.uniq
  @introspectors.reject { |i| disabled.include?(i) }
end

#excluded_table?(table_name) ⇒ Boolean

Whether a table name matches any #excluded_tables pattern (exact or glob).

Parameters:

  • table_name (String, nil)

Returns:

  • (Boolean)


154
155
156
157
158
# File 'lib/rails_ai_bridge/config/introspection.rb', line 154

def excluded_table?(table_name)
  return false if table_name.nil? || table_name.to_s.empty?

  @excluded_tables.any? { |pat| ExclusionHelper.table_pattern_match?(pat.to_s, table_name.to_s) }
end