Class: RuboCop::Cop::Legion::HelperMigration::DirectLlmEmbed
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::Legion::HelperMigration::DirectLlmEmbed
- Extended by:
- AutoCorrector
- Defined in:
- lib/rubocop/cop/legion/helper_migration/direct_llm_embed.rb
Overview
Detects direct calls to ‘Legion::LLM.embed` and suggests using the `llm_embed` helper from `Legion::Extensions::Helpers::LLM`.
Constant Summary collapse
- MSG =
'Use `llm_embed` instead of `Legion::LLM.embed`. ' \ 'Include `Legion::Extensions::Helpers::LLM` via the LLM helper mixin.'
- RESTRICT_ON_SEND =
%i[embed].freeze
Instance Method Summary collapse
Instance Method Details
#legion_llm_embed?(node) ⇒ Object
27 28 29 |
# File 'lib/rubocop/cop/legion/helper_migration/direct_llm_embed.rb', line 27 def_node_matcher :legion_llm_embed?, <<~PATTERN (send (const (const nil? :Legion) :LLM) :embed ...) PATTERN |
#on_send(node) ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/rubocop/cop/legion/helper_migration/direct_llm_embed.rb', line 31 def on_send(node) return unless (node) add_offense(node, message: MSG) do |corrector| args_source = node.arguments.map(&:source).join(', ') corrector.replace(node, "llm_embed(#{args_source})") end end |