Class: RailsAiContext::Tools::GetHelperMethods

Inherits:
BaseTool
  • Object
show all
Defined in:
lib/rails_ai_context/tools/get_helper_methods.rb

Constant Summary collapse

FRAMEWORK_HELPERS =

Common framework helpers to detect usage of

{
  "Devise" => %w[current_user user_signed_in? authenticate_user! current_admin admin_signed_in? authenticate_admin!],
  "Pagy" => %w[pagy_nav pagy_info pagy_nav_js pagy_combo_nav_js pagy_items_selector_js],
  "Turbo" => %w[turbo_stream_from turbo_frame_tag turbo_stream],
  "Pundit" => %w[policy authorize pundit_user],
  "CanCanCan" => %w[can? cannot? authorize!],
  "Kaminari" => %w[paginate page_entries_info],
  "WillPaginate" => %w[will_paginate page_entries_info],
  "SimpleForm" => %w[simple_form_for simple_fields_for],
  "Draper" => %w[decorate decorated?],
  "InlineSvg" => %w[inline_svg_tag inline_svg],
  "MetaTags" => %w[set_meta_tags display_meta_tags]
}.freeze

Constants inherited from BaseTool

BaseTool::SESSION_CONTEXT, BaseTool::SHARED_CACHE

Class Method Summary collapse

Methods inherited from BaseTool

abstract!, abstract?, cache_key, cached_context, config, extract_method_source_from_file, extract_method_source_from_string, find_closest_match, fuzzy_find_key, inherited, not_found_response, paginate, rails_app, registered_tools, reset_all_caches!, reset_cache!, session_queries, session_record, session_reset!, set_call_params, text_response

Class Method Details

.call(helper: nil, detail: "standard", offset: 0, limit: nil, server_context: nil) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/rails_ai_context/tools/get_helper_methods.rb', line 50

def self.call(helper: nil, detail: "standard", offset: 0, limit: nil, server_context: nil)
  root = rails_app.root.to_s
  helpers_dir = File.join(root, "app", "helpers")
  max_size = RailsAiContext.configuration.max_file_size

  unless Dir.exist?(helpers_dir)
    return text_response("No app/helpers/ directory found.")
  end

  helper_files = Dir.glob(File.join(helpers_dir, "**", "*.rb")).sort

  if helper_files.empty?
    return text_response("No helper files found in app/helpers/.")
  end

  # Specific helper — full detail
  if helper
    return show_helper(helper, helper_files, helpers_dir, root, max_size, detail)
  end

  # List all helpers
  list_helpers(helper_files, helpers_dir, root, max_size, detail, offset: offset, limit: limit)
end