Class: Kward::CodeSearch
- Inherits:
-
Object
- Object
- Kward::CodeSearch
- Defined in:
- lib/kward/tools/search/code.rb
Defined Under Namespace
Classes: GitRunner, NetHttpClient
Constant Summary collapse
- DEFAULT_MAX_RESULTS =
10- MAX_MAX_RESULTS =
50- DEFAULT_CONTEXT_LINES =
2- DEFAULT_LINE_COUNT =
200- MAX_LINE_COUNT =
400- MAX_FILE_BYTES =
512 * 1024
- MAX_SCANNED_FILES =
5_000- MAX_OUTPUT_BYTES =
16 * 1024
- HTTP_TIMEOUT_SECONDS =
10- ECOSYSTEMS =
%w[rubygems npm pypi crates go].freeze
- ACTIONS =
%w[package_search github_search repo_clone repo_search repo_read list_cache refresh_cache clear_cache].freeze
Instance Method Summary collapse
- #call(args) ⇒ Object
-
#initialize(cache_root: nil, http_client: NetHttpClient.new, git_runner: GitRunner.new, max_output_bytes: MAX_OUTPUT_BYTES) ⇒ CodeSearch
constructor
A new instance of CodeSearch.
Constructor Details
#initialize(cache_root: nil, http_client: NetHttpClient.new, git_runner: GitRunner.new, max_output_bytes: MAX_OUTPUT_BYTES) ⇒ CodeSearch
Returns a new instance of CodeSearch.
24 25 26 27 28 29 |
# File 'lib/kward/tools/search/code.rb', line 24 def initialize(cache_root: nil, http_client: NetHttpClient.new, git_runner: GitRunner.new, max_output_bytes: MAX_OUTPUT_BYTES) @cache_root = File.(cache_root || ConfigFiles.code_search_cache_dir) @http_client = http_client @git_runner = git_runner @max_output_bytes = max_output_bytes end |
Instance Method Details
#call(args) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/kward/tools/search/code.rb', line 31 def call(args) action = value(args, "action").to_s return "Error: action must be one of: #{ACTIONS.join(", ")}" unless ACTIONS.include?(action) case action when "package_search" then package_search(args) when "github_search" then github_search_action(args) when "repo_clone" then repo_clone(args) when "repo_search" then repo_search(args) when "repo_read" then repo_read(args) when "list_cache" then list_cache when "refresh_cache" then refresh_cache(args) when "clear_cache" then clear_cache(args) end rescue StandardError => e "Error: code_search failed: #{redact(e.)}" end |