rails-ai-context 5.30.2 → 5.32.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +868 -0
- data/CONTEXT.md +7 -3
- data/README.md +1 -1
- data/docs/ARCHITECTURE.md +3 -3
- data/docs/CLI.md +1 -1
- data/docs/COMPATIBILITY.md +50 -14
- data/docs/CONFIGURATION.md +4 -1
- data/docs/FAQ.md +1 -1
- data/docs/GUIDE.md +14 -8
- data/docs/INTROSPECTORS.md +50 -23
- data/docs/SECURITY.md +56 -1
- data/docs/TOOLS.md +58 -12
- data/lib/generators/rails_ai_context/install/install_generator.rb +1 -0
- data/lib/rails_ai_context/action_filters.rb +121 -48
- data/lib/rails_ai_context/app_commands.rb +2 -2
- data/lib/rails_ai_context/app_kind.rb +65 -8
- data/lib/rails_ai_context/ast_cache.rb +53 -18
- data/lib/rails_ai_context/base_mixins.rb +46 -16
- data/lib/rails_ai_context/boot_manager.rb +5 -1
- data/lib/rails_ai_context/cli/entry_boot.rb +17 -2
- data/lib/rails_ai_context/cli/tool_runner.rb +15 -1
- data/lib/rails_ai_context/concern_macros.rb +791 -111
- data/lib/rails_ai_context/concern_membership.rb +25 -5
- data/lib/rails_ai_context/concern_paths.rb +63 -17
- data/lib/rails_ai_context/config_yaml.rb +40 -0
- data/lib/rails_ai_context/configuration.rb +3 -3
- data/lib/rails_ai_context/data/docs/index.json +324 -0
- data/lib/rails_ai_context/database_yml.rb +136 -0
- data/lib/rails_ai_context/doctor.rb +30 -37
- data/lib/rails_ai_context/erb_source.rb +40 -0
- data/lib/rails_ai_context/fingerprinter.rb +48 -22
- data/lib/rails_ai_context/fixture_keys.rb +42 -1
- data/lib/rails_ai_context/gem_lock.rb +275 -47
- data/lib/rails_ai_context/git_ignore.rb +13 -11
- data/lib/rails_ai_context/hydrators/hydration_formatter.rb +8 -2
- data/lib/rails_ai_context/hydrators/schema_hint_builder.rb +10 -5
- data/lib/rails_ai_context/introspector.rb +10 -1
- data/lib/rails_ai_context/introspectors/action_mailbox_introspector.rb +27 -19
- data/lib/rails_ai_context/introspectors/action_presence.rb +11 -8
- data/lib/rails_ai_context/introspectors/action_resolver.rb +38 -26
- data/lib/rails_ai_context/introspectors/action_text_introspector.rb +2 -2
- data/lib/rails_ai_context/introspectors/active_record_settings.rb +56 -0
- data/lib/rails_ai_context/introspectors/active_storage_introspector.rb +1 -1
- data/lib/rails_ai_context/introspectors/active_support_introspector.rb +98 -22
- data/lib/rails_ai_context/introspectors/admin_resources.rb +101 -0
- data/lib/rails_ai_context/introspectors/anyway_configs.rb +64 -0
- data/lib/rails_ai_context/introspectors/apartment_config.rb +47 -0
- data/lib/rails_ai_context/introspectors/api_introspector.rb +125 -26
- data/lib/rails_ai_context/introspectors/asset_pipeline_introspector.rb +24 -19
- data/lib/rails_ai_context/introspectors/ast_walk.rb +18 -0
- data/lib/rails_ai_context/introspectors/auth_introspector.rb +71 -18
- data/lib/rails_ai_context/introspectors/autoload_introspector.rb +62 -15
- data/lib/rails_ai_context/introspectors/base.rb +38 -0
- data/lib/rails_ai_context/introspectors/call_site_expansion.rb +349 -39
- data/lib/rails_ai_context/introspectors/component_introspector.rb +26 -14
- data/lib/rails_ai_context/introspectors/config_introspector.rb +22 -9
- data/lib/rails_ai_context/introspectors/connection_pool_introspector.rb +1 -4
- data/lib/rails_ai_context/introspectors/controller_filters.rb +335 -31
- data/lib/rails_ai_context/introspectors/controller_introspector.rb +315 -129
- data/lib/rails_ai_context/introspectors/controller_settings.rb +182 -0
- data/lib/rails_ai_context/introspectors/convention_introspector.rb +18 -15
- data/lib/rails_ai_context/introspectors/database_stats_introspector.rb +1 -1
- data/lib/rails_ai_context/introspectors/declared_constant.rb +108 -23
- data/lib/rails_ai_context/introspectors/eager_load.rb +12 -7
- data/lib/rails_ai_context/introspectors/engine_introspector.rb +13 -5
- data/lib/rails_ai_context/introspectors/env_config_introspector.rb +62 -17
- data/lib/rails_ai_context/introspectors/env_introspector.rb +8 -6
- data/lib/rails_ai_context/introspectors/env_references.rb +21 -4
- data/lib/rails_ai_context/introspectors/frontend_framework_introspector.rb +37 -22
- data/lib/rails_ai_context/introspectors/gem_introspector.rb +3 -1
- data/lib/rails_ai_context/introspectors/gemfile_gems.rb +53 -5
- data/lib/rails_ai_context/introspectors/grape_endpoints.rb +109 -0
- data/lib/rails_ai_context/introspectors/helper_names.rb +12 -1
- data/lib/rails_ai_context/introspectors/i18n_introspector.rb +101 -46
- data/lib/rails_ai_context/introspectors/includers.rb +6 -1
- data/lib/rails_ai_context/introspectors/initializer_introspector.rb +2 -5
- data/lib/rails_ai_context/introspectors/job_introspector.rb +548 -103
- data/lib/rails_ai_context/introspectors/listener_registration.rb +11 -1
- data/lib/rails_ai_context/introspectors/listeners/associations_listener.rb +51 -4
- data/lib/rails_ai_context/introspectors/listeners/autoload_ignore_listener.rb +31 -0
- data/lib/rails_ai_context/introspectors/listeners/autoload_paths_listener.rb +4 -47
- data/lib/rails_ai_context/introspectors/listeners/base_listener.rb +80 -14
- data/lib/rails_ai_context/introspectors/listeners/branch_conditions.rb +156 -0
- data/lib/rails_ai_context/introspectors/listeners/callbacks_listener.rb +85 -23
- data/lib/rails_ai_context/introspectors/listeners/class_definition_listener.rb +35 -6
- data/lib/rails_ai_context/introspectors/listeners/component_structure_listener.rb +30 -2
- data/lib/rails_ai_context/introspectors/listeners/conditional_macro_listener.rb +19 -0
- data/lib/rails_ai_context/introspectors/listeners/config_assignment_listener.rb +255 -10
- data/lib/rails_ai_context/introspectors/listeners/constant_reference_listener.rb +34 -0
- data/lib/rails_ai_context/introspectors/listeners/constructor_macro_listener.rb +123 -0
- data/lib/rails_ai_context/introspectors/listeners/definition_file_paths_listener.rb +66 -0
- data/lib/rails_ai_context/introspectors/listeners/enums_listener.rb +2 -2
- data/lib/rails_ai_context/introspectors/listeners/env_access_listener.rb +31 -0
- data/lib/rails_ai_context/introspectors/listeners/filter_macro_listener.rb +54 -0
- data/lib/rails_ai_context/introspectors/listeners/fixture_paths_listener.rb +62 -0
- data/lib/rails_ai_context/introspectors/listeners/gemfile_dsl_listener.rb +42 -1
- data/lib/rails_ai_context/introspectors/listeners/generic_macro_listener.rb +28 -2
- data/lib/rails_ai_context/introspectors/listeners/grape_api_listener.rb +137 -0
- data/lib/rails_ai_context/introspectors/listeners/http_client_call_listener.rb +50 -0
- data/lib/rails_ai_context/introspectors/listeners/i18n_load_path_listener.rb +54 -0
- data/lib/rails_ai_context/introspectors/listeners/literal_paths.rb +123 -0
- data/lib/rails_ai_context/introspectors/listeners/macros_listener.rb +248 -4
- data/lib/rails_ai_context/introspectors/listeners/mailbox_routing_listener.rb +2 -1
- data/lib/rails_ai_context/introspectors/listeners/method_call_listener.rb +7 -1
- data/lib/rails_ai_context/introspectors/listeners/methods_listener.rb +352 -69
- data/lib/rails_ai_context/introspectors/listeners/migration_dsl_listener.rb +1 -1
- data/lib/rails_ai_context/introspectors/listeners/migration_replay_listener.rb +35 -26
- data/lib/rails_ai_context/introspectors/listeners/mixins_listener.rb +62 -29
- data/lib/rails_ai_context/introspectors/listeners/mount_listener.rb +8 -0
- data/lib/rails_ai_context/introspectors/listeners/namespaced_roots_listener.rb +35 -0
- data/lib/rails_ai_context/introspectors/listeners/nested_constants_listener.rb +32 -0
- data/lib/rails_ai_context/introspectors/listeners/owner_scope.rb +67 -0
- data/lib/rails_ai_context/introspectors/listeners/preview_paths_listener.rb +16 -7
- data/lib/rails_ai_context/introspectors/listeners/proc_literal_listener.rb +42 -0
- data/lib/rails_ai_context/introspectors/listeners/queue_assignment_listener.rb +54 -0
- data/lib/rails_ai_context/introspectors/listeners/rake_task_dsl_listener.rb +21 -8
- data/lib/rails_ai_context/introspectors/listeners/route_files_listener.rb +4 -11
- data/lib/rails_ai_context/introspectors/listeners/routes_dsl_listener.rb +461 -65
- data/lib/rails_ai_context/introspectors/listeners/schema_dsl_listener.rb +76 -14
- data/lib/rails_ai_context/introspectors/listeners/scopes_listener.rb +40 -1
- data/lib/rails_ai_context/introspectors/listeners/validations_listener.rb +10 -1
- data/lib/rails_ai_context/introspectors/listeners/view_paths_listener.rb +37 -0
- data/lib/rails_ai_context/introspectors/middleware_introspector.rb +47 -3
- data/lib/rails_ai_context/introspectors/migration_introspector.rb +3 -3
- data/lib/rails_ai_context/introspectors/migration_replay/helpers.rb +4 -3
- data/lib/rails_ai_context/introspectors/migration_replay/statements.rb +72 -12
- data/lib/rails_ai_context/introspectors/migration_replay.rb +110 -14
- data/lib/rails_ai_context/introspectors/model_introspector.rb +708 -214
- data/lib/rails_ai_context/introspectors/module_aliases.rb +11 -3
- data/lib/rails_ai_context/introspectors/multi_database_introspector.rb +9 -57
- data/lib/rails_ai_context/introspectors/observability_introspector.rb +5 -8
- data/lib/rails_ai_context/introspectors/performance_introspector.rb +28 -8
- data/lib/rails_ai_context/introspectors/rake_task_introspector.rb +118 -51
- data/lib/rails_ai_context/introspectors/recurring_schedules.rb +150 -0
- data/lib/rails_ai_context/introspectors/rendered_record.rb +87 -0
- data/lib/rails_ai_context/introspectors/retry_policy.rb +8 -5
- data/lib/rails_ai_context/introspectors/route_introspector.rb +153 -42
- data/lib/rails_ai_context/introspectors/schema_conventions.rb +127 -40
- data/lib/rails_ai_context/introspectors/schema_dump_path.rb +80 -0
- data/lib/rails_ai_context/introspectors/schema_introspector.rb +346 -112
- data/lib/rails_ai_context/introspectors/schema_reader.rb +69 -29
- data/lib/rails_ai_context/introspectors/service_classes.rb +21 -15
- data/lib/rails_ai_context/introspectors/source_calls.rb +1 -1
- data/lib/rails_ai_context/introspectors/source_introspector.rb +17 -2
- data/lib/rails_ai_context/introspectors/source_scan.rb +174 -26
- data/lib/rails_ai_context/introspectors/sqlite_virtual_tables.rb +28 -0
- data/lib/rails_ai_context/introspectors/stimulus_introspector.rb +16 -5
- data/lib/rails_ai_context/introspectors/structure_sql_reader.rb +372 -98
- data/lib/rails_ai_context/introspectors/superclass_chain.rb +14 -15
- data/lib/rails_ai_context/introspectors/table_name.rb +46 -45
- data/lib/rails_ai_context/introspectors/test_introspector.rb +289 -78
- data/lib/rails_ai_context/introspectors/turbo_introspector.rb +10 -5
- data/lib/rails_ai_context/introspectors/view_introspector.rb +5 -40
- data/lib/rails_ai_context/introspectors/view_template_introspector.rb +12 -10
- data/lib/rails_ai_context/method_name.rb +31 -0
- data/lib/rails_ai_context/migration_status.rb +5 -5
- data/lib/rails_ai_context/output_guard.rb +6 -4
- data/lib/rails_ai_context/package_json.rb +96 -5
- data/lib/rails_ai_context/path_resolver.rb +170 -15
- data/lib/rails_ai_context/payload.rb +48 -0
- data/lib/rails_ai_context/pending_migrations.rb +15 -18
- data/lib/rails_ai_context/portable_path.rb +76 -4
- data/lib/rails_ai_context/redaction.rb +8 -2
- data/lib/rails_ai_context/route_coverage.rb +5 -1
- data/lib/rails_ai_context/safe_file.rb +4 -1
- data/lib/rails_ai_context/safe_path.rb +61 -10
- data/lib/rails_ai_context/schema_hint.rb +8 -2
- data/lib/rails_ai_context/schema_version.rb +7 -9
- data/lib/rails_ai_context/serializers/claude_rules_serializer.rb +1 -1
- data/lib/rails_ai_context/serializers/markdown_serializer.rb +13 -4
- data/lib/rails_ai_context/serializers/section_facts.rb +5 -1
- data/lib/rails_ai_context/serializers/stack_overview_helper.rb +2 -2
- data/lib/rails_ai_context/serializers/tool_guide_helper.rb +7 -4
- data/lib/rails_ai_context/server.rb +26 -7
- data/lib/rails_ai_context/test_framework.rb +32 -5
- data/lib/rails_ai_context/tools/analyze_feature.rb +22 -10
- data/lib/rails_ai_context/tools/base_tool.rb +69 -30
- data/lib/rails_ai_context/tools/diagnose.rb +1 -1
- data/lib/rails_ai_context/tools/generate_test.rb +8 -9
- data/lib/rails_ai_context/tools/get_active_support.rb +19 -4
- data/lib/rails_ai_context/tools/get_api.rb +17 -11
- data/lib/rails_ai_context/tools/get_autoload.rb +10 -5
- data/lib/rails_ai_context/tools/get_callbacks.rb +65 -14
- data/lib/rails_ai_context/tools/get_component_catalog.rb +7 -4
- data/lib/rails_ai_context/tools/get_concern.rb +31 -18
- data/lib/rails_ai_context/tools/get_config.rb +52 -18
- data/lib/rails_ai_context/tools/get_controllers.rb +57 -13
- data/lib/rails_ai_context/tools/get_conventions.rb +44 -22
- data/lib/rails_ai_context/tools/get_engines.rb +2 -0
- data/lib/rails_ai_context/tools/get_env.rb +209 -52
- data/lib/rails_ai_context/tools/get_env_config.rb +38 -7
- data/lib/rails_ai_context/tools/get_frontend_stack.rb +56 -7
- data/lib/rails_ai_context/tools/get_helper_methods.rb +136 -26
- data/lib/rails_ai_context/tools/get_job_pattern.rb +143 -87
- data/lib/rails_ai_context/tools/get_mailers.rb +59 -2
- data/lib/rails_ai_context/tools/get_model_details.rb +178 -28
- data/lib/rails_ai_context/tools/get_partial_interface.rb +101 -62
- data/lib/rails_ai_context/tools/get_routes.rb +35 -9
- data/lib/rails_ai_context/tools/get_schema.rb +160 -61
- data/lib/rails_ai_context/tools/get_service_pattern.rb +121 -25
- data/lib/rails_ai_context/tools/get_stimulus.rb +1 -1
- data/lib/rails_ai_context/tools/get_test_info.rb +152 -82
- data/lib/rails_ai_context/tools/get_view.rb +37 -20
- data/lib/rails_ai_context/tools/migration_advisor.rb +64 -24
- data/lib/rails_ai_context/tools/onboard.rb +174 -88
- data/lib/rails_ai_context/tools/performance_check.rb +5 -13
- data/lib/rails_ai_context/tools/query.rb +122 -28
- data/lib/rails_ai_context/tools/read_logs.rb +45 -17
- data/lib/rails_ai_context/tools/runtime_info.rb +1 -1
- data/lib/rails_ai_context/tools/safe_call.rb +20 -15
- data/lib/rails_ai_context/tools/search_code.rb +114 -40
- data/lib/rails_ai_context/tools/search_docs.rb +22 -11
- data/lib/rails_ai_context/tools/security_scan.rb +51 -4
- data/lib/rails_ai_context/tools/validate.rb +21 -4
- data/lib/rails_ai_context/tools/validate_semantics.rb +18 -6
- data/lib/rails_ai_context/version.rb +1 -1
- data/lib/rails_ai_context/vfs.rb +2 -2
- data/lib/rails_ai_context/view_file.rb +53 -3
- data/lib/rails_ai_context.rb +10 -2
- data/server.json +1 -1
- metadata +34 -3
|
@@ -28,7 +28,8 @@ module RailsAiContext
|
|
|
28
28
|
middleware_stack: extract_middleware,
|
|
29
29
|
initializers: extract_initializers,
|
|
30
30
|
credentials_configured: credentials_configured?,
|
|
31
|
-
current_attributes:
|
|
31
|
+
current_attributes: current_attributes.keys,
|
|
32
|
+
current_attribute_details: current_attributes.presence,
|
|
32
33
|
error_monitoring: detect_error_monitoring
|
|
33
34
|
}
|
|
34
35
|
|
|
@@ -100,10 +101,8 @@ module RailsAiContext
|
|
|
100
101
|
end
|
|
101
102
|
|
|
102
103
|
def extract_initializers
|
|
103
|
-
dir = File.join(root, "config/initializers")
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
Dir.glob(File.join(dir, "*.rb")).map { |f| File.basename(f) }.sort
|
|
104
|
+
dir = File.join(root, "config/initializers/")
|
|
105
|
+
PathResolver.initializer_paths(root).map { |path| path.delete_prefix(dir) }
|
|
107
106
|
end
|
|
108
107
|
|
|
109
108
|
# Returns whether credentials are configured (boolean).
|
|
@@ -115,13 +114,27 @@ module RailsAiContext
|
|
|
115
114
|
RailsAiContext.debug_fail(e, false, label: "credentials_configured?")
|
|
116
115
|
end
|
|
117
116
|
|
|
118
|
-
|
|
119
|
-
|
|
117
|
+
CURRENT_ATTRIBUTE_BASES = %w[ActiveSupport::CurrentAttributes Rails::CurrentAttributes].freeze
|
|
118
|
+
RESET_HOOKS = %i[resets after_reset before_reset].freeze
|
|
120
119
|
|
|
121
|
-
|
|
120
|
+
# class name => the attributes it declares and its reset hooks. declarations is the
|
|
121
|
+
# shared reader cached per tree, so the macro walk is the one walk, on matching classes only.
|
|
122
|
+
def current_attributes
|
|
123
|
+
@current_attributes ||= model_classes.filter_map do |name, record|
|
|
122
124
|
declared = DeclaredConstant.declarations(record.source).first
|
|
123
|
-
name if declared &&
|
|
125
|
+
[ name, current_attribute_detail(record.source) ] if declared && CURRENT_ATTRIBUTE_BASES.include?(declared.superclass)
|
|
126
|
+
end.to_h
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
def current_attribute_detail(source)
|
|
130
|
+
calls = SourceIntrospector.walk_source(source, {
|
|
131
|
+
calls: -> { Listeners::GenericMacroListener.new(:attribute, *RESET_HOOKS) }
|
|
132
|
+
})[:calls]
|
|
133
|
+
attributes = calls.select { |call| call[:macro] == :attribute }.flat_map do |call|
|
|
134
|
+
default = call[:option_nodes][:default]&.slice
|
|
135
|
+
call[:args].map { |name| default ? { name: name.to_s, default: default } : { name: name.to_s } }
|
|
124
136
|
end
|
|
137
|
+
{ attributes: attributes, hooks: calls.map { |call| call[:macro].to_s }.reject { |m| m == "attribute" }.uniq }
|
|
125
138
|
end
|
|
126
139
|
|
|
127
140
|
def detect_error_monitoring
|
|
@@ -104,10 +104,7 @@ module RailsAiContext
|
|
|
104
104
|
# Detect via the middleware stack + initializer references.
|
|
105
105
|
def detect_automatic_shard_selector
|
|
106
106
|
return true if app.middleware.any? { |m| (m.name || m.klass.to_s).include?("ShardSelector") }
|
|
107
|
-
|
|
108
|
-
return false unless Dir.exist?(init_dir)
|
|
109
|
-
|
|
110
|
-
Dir.glob(File.join(init_dir, "*.rb")).any? do |path|
|
|
107
|
+
PathResolver.initializer_paths(root).any? do |path|
|
|
111
108
|
content = RailsAiContext::SafeFile.read(path) or next false
|
|
112
109
|
content.include?("ShardSelector") || content.include?("connected_to role:")
|
|
113
110
|
end
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require "set"
|
|
4
|
+
|
|
3
5
|
module RailsAiContext
|
|
4
6
|
module Introspectors
|
|
5
7
|
# One reader for the filter macros a controller body declares.
|
|
@@ -10,78 +12,377 @@ module RailsAiContext
|
|
|
10
12
|
# `before_action` in ApplicationController reached the generated overview
|
|
11
13
|
# through its own file read and reached no tool at all.
|
|
12
14
|
module ControllerFilters
|
|
13
|
-
|
|
15
|
+
# Macros a gem defines to add one callback, with the gem: cancancan's controller_additions.rb
|
|
16
|
+
# (load and authorize blocks, check_authorization after) and acts_as_tenant's
|
|
17
|
+
# controller extensions, which add a named before_action.
|
|
18
|
+
GEM_FILTERS = {
|
|
19
|
+
load_and_authorize_resource: [ :before_action, :load_and_authorize_resource, "cancancan" ],
|
|
20
|
+
load_resource: [ :before_action, :load_resource, "cancancan" ],
|
|
21
|
+
authorize_resource: [ :before_action, :authorize_resource, "cancancan" ],
|
|
22
|
+
check_authorization: [ :after_action, :check_authorization, "cancancan" ],
|
|
23
|
+
skip_authorization_check: [ :before_action, :skip_authorization_check, "cancancan" ],
|
|
24
|
+
set_current_tenant_by_subdomain: [ :before_action, :find_tenant_by_subdomain, "acts_as_tenant" ],
|
|
25
|
+
set_current_tenant_by_subdomain_or_domain: [ :before_action, :find_tenant_by_subdomain_or_domain, "acts_as_tenant" ]
|
|
26
|
+
}.freeze
|
|
27
|
+
|
|
28
|
+
# cancancan's controller_resource.rb adds these with prepend_before_action when passed `prepend: true`.
|
|
29
|
+
GEM_PREPENDABLE = %i[load_and_authorize_resource load_resource authorize_resource].freeze
|
|
30
|
+
|
|
31
|
+
MACROS = (%i[
|
|
14
32
|
before_action after_action around_action
|
|
15
33
|
prepend_before_action append_before_action
|
|
16
|
-
|
|
17
|
-
|
|
34
|
+
prepend_after_action prepend_around_action append_after_action append_around_action
|
|
35
|
+
skip_before_action skip_after_action skip_around_action skip_forgery_protection
|
|
36
|
+
http_basic_authenticate_with
|
|
37
|
+
] + GEM_FILTERS.keys).freeze
|
|
38
|
+
|
|
39
|
+
# The block filter http_authentication.rb adds, named for the macro: its keywords are credentials.
|
|
40
|
+
BASIC_AUTH = { macro: :before_action, args: [ :http_basic_authenticate_with ], callbacks: nil, proc_lines: [] }.freeze
|
|
41
|
+
|
|
42
|
+
# actionpack's request_forgery_protection.rb defines it as this skip.
|
|
43
|
+
FORGERY_SKIP = { macro: :skip_before_action, args: [ :verify_authenticity_token ] }.freeze
|
|
18
44
|
|
|
19
45
|
LISTENERS = {
|
|
20
|
-
filters: -> { Listeners::
|
|
21
|
-
|
|
46
|
+
filters: -> { Listeners::FilterMacroListener.new(*MACROS) },
|
|
47
|
+
nested: Listeners::NestedConstantsListener,
|
|
48
|
+
mixins: Listeners::MixinsListener,
|
|
49
|
+
# A macro inside a `def` runs when the method is called, so ConcernMacros holds it back by these.
|
|
50
|
+
methods: Listeners::MethodsListener
|
|
22
51
|
}.freeze
|
|
23
52
|
|
|
53
|
+
# The class body's receiverless calls by name, read only once a mixin's class method declares a filter.
|
|
54
|
+
# A class method the chain defines makes its own calls where a call of it runs
|
|
55
|
+
# (`def self.public_page = allow_unauthenticated_access only: :show`), each listed as Relayed.
|
|
56
|
+
CallSites = Struct.new(:source, :defs) do
|
|
57
|
+
def sites_by_name
|
|
58
|
+
@sites_by_name ||= begin
|
|
59
|
+
tree = AstCache.parse_string(source)&.value
|
|
60
|
+
sites = tree ? SourceIntrospector.calls_outside_methods(tree, self_receiver: true) : {}
|
|
61
|
+
defs ? ControllerFilters.relayed(sites, defs.call) : sites
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
# The body's calls and the calls its concerns' blocks make, all run with the class as self.
|
|
67
|
+
Sites = Struct.new(:body, :blocks) do
|
|
68
|
+
def sites_by_name
|
|
69
|
+
@sites_by_name ||= ConcernMacros::Run.merge_calls(ConcernMacros::Run.merge_calls({}, body.sites_by_name), blocks)
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
24
73
|
module_function
|
|
25
74
|
|
|
26
75
|
# @param source [String] one controller's Ruby source
|
|
27
76
|
# @return [Array<Hash>] { name:, kind:, skipped:/declared:, only:, except:, if:, unless: }
|
|
28
|
-
def from_source(source)
|
|
29
|
-
walk(source)
|
|
77
|
+
def from_source(source, root: nil)
|
|
78
|
+
walked = walk(source)
|
|
79
|
+
SourceIntrospector.class_level(walked[:filters], walked).flat_map { |entry| record(entry, root) }
|
|
30
80
|
rescue => e
|
|
31
81
|
RailsAiContext.debug_fail(e, [], label: "controller filter read")
|
|
32
82
|
end
|
|
33
83
|
|
|
34
84
|
# The class body's filters and every included concern's, in Rails' order: an `include`
|
|
35
|
-
# adds its concern's filters where it stands, each named in `from_concern`.
|
|
85
|
+
# adds its concern's filters where it stands, each named in `from_concern`. A class
|
|
86
|
+
# method the body calls (`allow_unauthenticated_access`) declares what its body does,
|
|
87
|
+
# with the call's options, where the call stands, wherever on the chain it is defined.
|
|
36
88
|
#
|
|
37
89
|
# @param within [String] the class's constant, for a namespace-relative `include`
|
|
38
90
|
# @param cache [Hash, nil] see ConcernMacros.collect
|
|
39
91
|
# @return [Array(Array<Hash>, Array<String>)] the filters, and the
|
|
40
92
|
# included modules whose file could not be read
|
|
41
93
|
def with_concerns(source, root:, within:, cache: nil)
|
|
94
|
+
# A tool reading each route's base controller walks the same concerns for every route.
|
|
95
|
+
cache ||= RunCache.fetch([ :controller_concern_walks ]) { {} }
|
|
42
96
|
walked = SourceIntrospector.walk_source(source, LISTENERS)
|
|
43
97
|
mixins = Array(walked[:mixins])
|
|
98
|
+
chain_defs = nil
|
|
99
|
+
calls = CallSites.new(source, -> { chain_defs ||= class_method_defs(source, mixins, within, root, cache) })
|
|
44
100
|
# One walk, so a concern two includes reach is added once, as Ruby does.
|
|
45
|
-
|
|
46
|
-
root, mixins, keys: [ :filters ], prefer: "controller", within: within, cache: cache, listeners: LISTENERS
|
|
101
|
+
found = ConcernMacros.collect(
|
|
102
|
+
root, mixins, keys: [ :filters ], prefer: "controller", within: within, cache: cache, calls: calls, listeners: LISTENERS
|
|
47
103
|
)
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
104
|
+
collected, placement, block_sites = found.collected, found.placement, found.block_sites
|
|
105
|
+
own_defs = singleton_expansions(source, walked, calls, Set.new)
|
|
106
|
+
defined = own_defs.map { |entry| entry[:site].name }.to_set
|
|
107
|
+
# A concern method the body calls declares for the body; one a concern's own block calls stays the concern's.
|
|
108
|
+
own_file = nil
|
|
109
|
+
filed = Array(collected[:filters]).map do |entry|
|
|
110
|
+
path = placement.dig(entry[:from_concern], 2)
|
|
111
|
+
own_file ||= [ base_source(root, within, nil)&.last ] if path
|
|
112
|
+
with_file(entry, path, root, own_file&.first)
|
|
113
|
+
end
|
|
114
|
+
by_body, by_concern = filed.partition { |entry| body_call?(entry, calls) }
|
|
115
|
+
called = by_body.reject { |entry| defined.include?(entry[:site].name) }
|
|
116
|
+
defined.merge(called.map { |entry| entry[:site].name })
|
|
117
|
+
defined.merge(by_concern.filter_map { |entry| entry[:site]&.name })
|
|
118
|
+
base_unread = []
|
|
119
|
+
inherited = base_expansions(source, within, root, Sites.new(calls, found.included_calls), defined, cache, base_unread)
|
|
120
|
+
# A base's method a concern's block calls declares where that concern is included.
|
|
121
|
+
from_blocks, inherited = inherited.partition { |entry| block_sites.key?(entry[:site].__id__) }
|
|
122
|
+
by_concern += from_blocks.map { |entry| entry.merge(from_concern: block_sites[entry[:site].__id__].first) }
|
|
123
|
+
# A class method the chain defines answers the call, not the gem's macro of that name.
|
|
124
|
+
own_level = SourceIntrospector.class_level(walked[:filters], walked)
|
|
125
|
+
if own_level.any? { |entry| GEM_FILTERS.key?(entry[:macro]) }
|
|
126
|
+
shadowed = calls.defs.call.keys.to_set(&:to_s)
|
|
127
|
+
own_level = own_level.reject { |entry| GEM_FILTERS.key?(entry[:macro]) && shadowed.include?(entry[:macro].to_s) }
|
|
128
|
+
end
|
|
129
|
+
placed = own_level.map { |entry| [ entry[:location].to_i, -1, 0, entry ] } +
|
|
130
|
+
(own_defs + called + inherited).map { |entry| [ ConcernMacros::Relayed.root(entry[:site]).location.start_line, -1, 0, entry.except(:site, :definer, :from_concern) ] } +
|
|
131
|
+
ConcernMacros.at_includes(by_concern, placement, mixins) { |entry| entry[:site] ? entry[:site].location.start_line : entry[:location].to_i }
|
|
132
|
+
entries = ConcernMacros.in_include_order(placed)
|
|
133
|
+
filters = entries.flat_map do |entry|
|
|
134
|
+
record(entry, root).map { |filter| entry[:from_concern] ? filter.merge(from_concern: entry[:from_concern]) : filter }
|
|
135
|
+
end
|
|
136
|
+
[ filters, found.unread | outside_modules(mixins, root, within) | base_unread ]
|
|
60
137
|
rescue => e
|
|
61
138
|
RailsAiContext.debug_fail(e, [ [], [] ], label: "controller filter read with concerns")
|
|
62
139
|
end
|
|
63
140
|
|
|
141
|
+
# actionpack and actionview declare callbacks only in class macros (allow_browser), so including one of theirs adds none.
|
|
142
|
+
SILENT_FRAMEWORK = "ActionView::"
|
|
143
|
+
|
|
144
|
+
# The walk skips a module excluded_concerns names, but a filter one adds
|
|
145
|
+
# (ActiveStorage::SetBlob's set_blob) still runs.
|
|
146
|
+
def outside_modules(mixins, root, within)
|
|
147
|
+
mixins.filter_map do |mixin|
|
|
148
|
+
name = mixin[:name].to_s
|
|
149
|
+
next unless mixin[:ancestor] && !mixin[:inline]
|
|
150
|
+
next unless ConcernMembership.candidate?(name) && ConcernMembership.excluded?(name) && !name.start_with?(SILENT_FRAMEWORK)
|
|
151
|
+
|
|
152
|
+
name unless ConcernPaths.module_source(root.to_s, name, prefer: "controller", within: within)
|
|
153
|
+
end
|
|
154
|
+
end
|
|
155
|
+
|
|
64
156
|
def walk(source)
|
|
65
|
-
SourceIntrospector.walk_source(source, LISTENERS.slice(:filters))
|
|
157
|
+
SourceIntrospector.walk_source(source, LISTENERS.slice(:filters, :methods, :nested))
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
# What the class methods `source` defines itself (`def self.x`, `class << self`) declare at
|
|
161
|
+
# each call `calls` makes of one, skipping the names in `taken`.
|
|
162
|
+
def singleton_expansions(source, walked, calls, taken)
|
|
163
|
+
declaring = Array(walked[:methods]).select { |m| m[:scope] == :class && !taken.include?(m[:name].to_s) }
|
|
164
|
+
declaring = declaring.select { |m| declares_filters?(walked, m) }
|
|
165
|
+
return [] if declaring.empty?
|
|
166
|
+
|
|
167
|
+
sites = calls.sites_by_name
|
|
168
|
+
declaring = declaring.select { |m| sites.key?(m[:name].to_s) }
|
|
169
|
+
return [] if declaring.empty?
|
|
170
|
+
|
|
171
|
+
tree = AstCache.parse_string(source).value
|
|
172
|
+
declaring.flat_map do |method|
|
|
173
|
+
definition = AstWalk.def_at(tree, method[:offset])
|
|
174
|
+
next [] unless definition
|
|
175
|
+
|
|
176
|
+
found, = ConcernMacros.expand_calls(definition, sites.fetch(method[:name].to_s), [ :filters ], LISTENERS) do |entry, call|
|
|
177
|
+
[ entry.merge(site: call) ]
|
|
178
|
+
end
|
|
179
|
+
Array(found[:filters])
|
|
180
|
+
end
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
# Whether the method's body holds a filter macro the walk saw.
|
|
184
|
+
def declares_filters?(walked, method)
|
|
185
|
+
range = method[:offset].to_i...method[:end_offset].to_i
|
|
186
|
+
Array(walked[:filters]).any? { |entry| range.cover?(entry[:offset].to_i) }
|
|
187
|
+
end
|
|
188
|
+
|
|
189
|
+
# What a class method an app-defined base or one of its concerns defines declares at
|
|
190
|
+
# each call this class makes of it, nearest base first. Adds to `unread` the modules
|
|
191
|
+
# a base includes that the walk could not read, as their filters reach this class too.
|
|
192
|
+
def base_expansions(source, within, root, calls, taken, cache, unread = [])
|
|
193
|
+
found = []
|
|
194
|
+
each_base(source, within, root, cache) do |label, base, _path, file, walked|
|
|
195
|
+
own = singleton_expansions(base, walked, calls, taken).map { |entry| entry.merge(file: file) }
|
|
196
|
+
taken.merge(own.map { |entry| entry[:site].name })
|
|
197
|
+
found_in = ConcernMacros.collect(root, Array(walked[:mixins]), keys: [ :filters ], prefer: "controller",
|
|
198
|
+
within: label, cache: cache, calls: calls, listeners: LISTENERS)
|
|
199
|
+
mixed = Array(found_in.collected[:filters]).select { |entry| body_call?(entry, calls) && !taken.include?(entry[:site].name) }
|
|
200
|
+
.map { |entry| with_file(entry, found_in.placement.dig(entry[:from_concern], 2), root) }
|
|
201
|
+
taken.merge(mixed.map { |entry| entry[:site].name })
|
|
202
|
+
found.concat(own + mixed)
|
|
203
|
+
unread.concat(Array(found_in.unread) | outside_modules(Array(walked[:mixins]), root, label))
|
|
204
|
+
end
|
|
205
|
+
found
|
|
206
|
+
end
|
|
207
|
+
|
|
208
|
+
# Each app-defined base of the class, nearest first: [constant, source, realpath, app-relative path, walk].
|
|
209
|
+
# Like the other chain walks it ends at the framework or a base it cannot read; `seen` ends a cycle.
|
|
210
|
+
def each_base(source, within, root, cache)
|
|
211
|
+
seen = Set.new
|
|
212
|
+
name, scope = superclass_of(source, within)
|
|
213
|
+
loop do
|
|
214
|
+
break unless name && root
|
|
215
|
+
|
|
216
|
+
label, base, path, file = base_source(root, name, scope)
|
|
217
|
+
break unless base && seen.add?(path)
|
|
218
|
+
|
|
219
|
+
# Every controller reaches ApplicationController, so its walk is read once per run.
|
|
220
|
+
key = [ :controller_base_walk, path, base ]
|
|
221
|
+
walked = cache ? (cache[key] ||= SourceIntrospector.walk_source(base, LISTENERS)) : RunCache.fetch(key) { SourceIntrospector.walk_source(base, LISTENERS) }
|
|
222
|
+
yield label, base, path, file, walked
|
|
223
|
+
name, scope = RunCache.fetch([ :controller_base_superclass, path, label ]) { superclass_of(base, label) }
|
|
224
|
+
end
|
|
225
|
+
end
|
|
226
|
+
|
|
227
|
+
# The class methods the class and its app-defined bases define, their own and their concerns', by name,
|
|
228
|
+
# nearest first as Ruby's lookup finds them.
|
|
229
|
+
def class_method_defs(source, mixins, within, root, cache)
|
|
230
|
+
found = {}
|
|
231
|
+
add = lambda do |text, owner, modules, label|
|
|
232
|
+
tree = AstCache.parse_string(text)&.value
|
|
233
|
+
bodies = tree ? DeclaredConstant.class_bodies(tree, label) : []
|
|
234
|
+
# A file whose class is spelled other than its constant still defines its methods somewhere in it.
|
|
235
|
+
scope = bodies.empty? ? Array(tree && AstWalk.each(tree).to_a) : bodies.flat_map { |body| AstWalk.scope(body) }
|
|
236
|
+
ConcernMacros::SingletonLookup.own_defs(scope, owner).each { |definition| found[definition.name] ||= definition }
|
|
237
|
+
given = ConcernMacros.collect(root, modules, keys: [ :filters ], prefer: "controller", within: label, cache: cache, listeners: LISTENERS).mixins
|
|
238
|
+
Array(given).reverse_each { |_, _, defs, _| defs.each_value { |list| list.each { |definition| found[definition.name] ||= definition } } }
|
|
239
|
+
end
|
|
240
|
+
add.call(source, within, mixins, within)
|
|
241
|
+
each_base(source, within, root, cache) { |label, base, path, _, walked| add.call(base, path, Array(walked[:mixins]), label) }
|
|
242
|
+
found
|
|
243
|
+
end
|
|
244
|
+
|
|
245
|
+
# `sites` with the calls each class method `defs` names makes in turn, bound to the call running it.
|
|
246
|
+
def relayed(sites, defs)
|
|
247
|
+
queue = sites.flat_map { |name, nodes| nodes.map { |node| [ name, node ] } }
|
|
248
|
+
read = Set.new
|
|
249
|
+
until queue.empty?
|
|
250
|
+
name, site = queue.shift
|
|
251
|
+
definition = defs[name]
|
|
252
|
+
next unless definition&.node && read.add?([ definition.key, ConcernMacros::Relayed.root(site).__id__ ])
|
|
253
|
+
|
|
254
|
+
text = CallSiteExpansion.rewritten(definition.node, site)
|
|
255
|
+
tree = text && AstCache.parse_string(text)&.value
|
|
256
|
+
next unless tree
|
|
257
|
+
|
|
258
|
+
SourceIntrospector.calls_outside_methods(tree, self_receiver: true).each do |inner, nodes|
|
|
259
|
+
nodes.each do |node|
|
|
260
|
+
call = ConcernMacros::Relayed.new(node, site, definition)
|
|
261
|
+
(sites[inner] ||= []) << call
|
|
262
|
+
queue << [ inner, call ]
|
|
263
|
+
end
|
|
264
|
+
end
|
|
265
|
+
end
|
|
266
|
+
sites
|
|
66
267
|
end
|
|
67
268
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
269
|
+
# Whether the entry is what a method declares at a call the class body makes.
|
|
270
|
+
def body_call?(entry, calls)
|
|
271
|
+
site = entry[:site]
|
|
272
|
+
site && Array(calls.sites_by_name[site.name.to_s]).any? { |call| call.equal?(site) }
|
|
273
|
+
end
|
|
274
|
+
|
|
275
|
+
# [superclass, the namespace it is written in] of the class `within` names in `source`.
|
|
276
|
+
def superclass_of(source, within)
|
|
277
|
+
written = DeclaredConstant.parent_declaration(source, within.to_s)&.superclass
|
|
278
|
+
return nil unless written
|
|
279
|
+
|
|
280
|
+
written.start_with?("::") ? [ written.delete_prefix("::"), nil ] : [ written, within ]
|
|
281
|
+
end
|
|
282
|
+
|
|
283
|
+
# [constant, source, realpath, app-relative path] of the app controller base the name resolves to, as Ruby looks it up.
|
|
284
|
+
def base_source(root, name, scope)
|
|
285
|
+
RunCache.fetch([ :controller_base, root.to_s, name, scope ]) do
|
|
286
|
+
ConcernPaths.candidate_names(name, scope).lazy.filter_map do |candidate|
|
|
287
|
+
RunCache.fetch([ :controller_base_source, root.to_s, candidate ]) { constant_source(root, candidate) }
|
|
288
|
+
end.first
|
|
289
|
+
end
|
|
290
|
+
end
|
|
291
|
+
|
|
292
|
+
def constant_source(root, candidate)
|
|
293
|
+
prefix = "#{root.to_s.chomp("/")}/"
|
|
294
|
+
underscored = "#{candidate.underscore}.rb"
|
|
295
|
+
PathResolver.controller_dirs(root.to_s).each do |dir|
|
|
296
|
+
file = dir.start_with?(prefix) && ConcernPaths.spelled(dir, underscored)
|
|
297
|
+
next unless file
|
|
298
|
+
|
|
299
|
+
relative = File.join(dir.delete_prefix(prefix), file)
|
|
300
|
+
source, resolution = SafePath.read(relative, under: root.to_s)
|
|
301
|
+
next unless source && (file == underscored || DeclaredConstant.declarations(source, path_name: candidate).any? { |d| d.name == candidate })
|
|
302
|
+
|
|
303
|
+
return [ candidate, source, resolution.realpath, relative ]
|
|
304
|
+
end
|
|
305
|
+
nil
|
|
306
|
+
end
|
|
71
307
|
|
|
308
|
+
# The file a block the entry declares sits in, when that is not the class's own.
|
|
309
|
+
def with_file(entry, path, root, own = nil)
|
|
310
|
+
file = path && PortablePath.relativize(path, root.to_s)
|
|
311
|
+
file && file != own ? entry.merge(file: file) : entry
|
|
312
|
+
end
|
|
313
|
+
|
|
314
|
+
BARE_BLOCK = /\A(?:block|lambda) \(line \d+\)\z/
|
|
315
|
+
|
|
316
|
+
# A block outside the class's own file names that file: two blocks on one line number are two callbacks.
|
|
317
|
+
# A lambda says so, as Proc#lambda? tells it from the block it may share a line with.
|
|
318
|
+
def block_name(line, file = nil, lambda: false)
|
|
319
|
+
"#{lambda ? 'lambda' : 'block'} (line #{line}#{" of #{file}" if file})"
|
|
320
|
+
end
|
|
321
|
+
|
|
322
|
+
# A class body's filters as a class elsewhere names them: its own blocks by the file it is in.
|
|
323
|
+
def in_file(filters, file)
|
|
324
|
+
return filters unless file
|
|
325
|
+
|
|
326
|
+
filters.map { |filter| filter[:name].to_s.match?(BARE_BLOCK) ? filter.merge(name: "#{filter[:name].to_s.chomp(")")} of #{file})") : filter }
|
|
327
|
+
end
|
|
328
|
+
|
|
329
|
+
def block?(name)
|
|
330
|
+
name.to_s.start_with?("block (line ", "lambda (line ")
|
|
331
|
+
end
|
|
332
|
+
|
|
333
|
+
# One filter per callback the call adds, a block or lambda named by its line.
|
|
334
|
+
def record(entry, root = nil)
|
|
335
|
+
entry = entry.merge(FORGERY_SKIP) if entry[:macro] == :skip_forgery_protection
|
|
336
|
+
entry = entry.merge(BASIC_AUTH) if entry[:macro] == :http_basic_authenticate_with
|
|
337
|
+
if (macro, name, gem = GEM_FILTERS[entry[:macro]])
|
|
338
|
+
return [] unless bundled?(gem, root)
|
|
339
|
+
|
|
340
|
+
macro = :prepend_before_action if GEM_PREPENDABLE.include?(entry[:macro]) && (entry[:options] || {})[:prepend] == true
|
|
341
|
+
entry = entry.merge(macro: macro, args: [ name ], callbacks: nil, proc_lines: [])
|
|
342
|
+
end
|
|
72
343
|
macro = entry[:macro].to_s
|
|
73
344
|
skipped = macro.start_with?("skip_")
|
|
345
|
+
names = positional_names(entry, skipped ? [] : Array(entry[:proc_lines]))
|
|
74
346
|
# An excluded name is framework noise only while it runs. A skip of it
|
|
75
347
|
# is the app's own decision, which the per-action answer reports.
|
|
76
|
-
|
|
348
|
+
names -= RailsAiContext.configuration.excluded_filters.map(&:to_s) unless skipped
|
|
349
|
+
return [] if names.empty?
|
|
77
350
|
|
|
78
|
-
|
|
351
|
+
kind = macro.sub(/_action\z/, "").sub(/\A(?:prepend|append|skip)_/, "")
|
|
79
352
|
# A skip states the opposite of what the plain kind says, so it has to
|
|
80
353
|
# survive the fold into `before`/`after`/`around`. A declaration marks
|
|
81
354
|
# the body that made it, so an ancestor's skip of the same name does
|
|
82
355
|
# not reach it.
|
|
83
|
-
skipped ?
|
|
84
|
-
|
|
356
|
+
mark = skipped ? { skipped: true } : { declared: true }
|
|
357
|
+
# Rails unshifts each name onto the chain the class inherited; ActionFilters places it.
|
|
358
|
+
mark[:prepend] = true if macro.start_with?("prepend_")
|
|
359
|
+
tail = constraints(entry)
|
|
360
|
+
names.map { |name| { name: name, kind: kind, **mark, **tail } }
|
|
361
|
+
end
|
|
362
|
+
|
|
363
|
+
# Whether the app's lockfile resolves the gem; an app whose gems are unknown is given the benefit.
|
|
364
|
+
def bundled?(gem, root)
|
|
365
|
+
return true unless root
|
|
366
|
+
|
|
367
|
+
lock = GemLock.for(root)
|
|
368
|
+
lock.missing? || lock.present?(gem)
|
|
369
|
+
end
|
|
370
|
+
|
|
371
|
+
# Each callback the call gives, in the order Rails adds them: positional arguments as written,
|
|
372
|
+
# the block last, each named by FilterMacroListener.
|
|
373
|
+
def positional_names(entry, lines)
|
|
374
|
+
callbacks = entry[:callbacks]
|
|
375
|
+
lines = lines.dup
|
|
376
|
+
named = Array(callbacks).filter_map do |kind, name|
|
|
377
|
+
case kind
|
|
378
|
+
when :name then name
|
|
379
|
+
when :block, :lambda then block_name(lines.shift, entry[:file], lambda: kind == :lambda)
|
|
380
|
+
when :object then "#{name} (object)"
|
|
381
|
+
when :unread then "#{name} (not read)"
|
|
382
|
+
end
|
|
383
|
+
end
|
|
384
|
+
named = Array(entry[:args]).map(&:to_s) if callbacks.blank?
|
|
385
|
+
named + lines.map { |line| block_name(line, entry[:file]) }
|
|
85
386
|
end
|
|
86
387
|
|
|
87
388
|
def constraints(entry)
|
|
@@ -93,6 +394,7 @@ module RailsAiContext
|
|
|
93
394
|
out[:only] = only if only&.any?
|
|
94
395
|
out[:except] = except if except&.any?
|
|
95
396
|
out[:unless] = condition_text(opts[:unless], sources[:unless]) if opts[:unless]
|
|
397
|
+
out[:condition] = entry[:condition] if entry[:condition]
|
|
96
398
|
if opts[:if]
|
|
97
399
|
# When the condition compares action_name the AST can say which
|
|
98
400
|
# action it names; that is worth more than the line itself.
|
|
@@ -140,7 +442,9 @@ module RailsAiContext
|
|
|
140
442
|
statements.body.first
|
|
141
443
|
end
|
|
142
444
|
|
|
143
|
-
private_class_method :walk, :
|
|
445
|
+
private_class_method :walk, :outside_modules, :singleton_expansions, :declares_filters?, :base_expansions, :each_base,
|
|
446
|
+
:class_method_defs,
|
|
447
|
+
:superclass_of, :base_source, :constant_source, :with_file, :body_call?, :record, :bundled?, :positional_names, :constraints, :condition_text, :normalize, :action_condition, :lambda_body
|
|
144
448
|
end
|
|
145
449
|
end
|
|
146
450
|
end
|