Module: RubyLLM::Mongoid::ActsAs
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/ruby_llm/mongoid/acts_as.rb
Overview
Provides acts_as_chat, acts_as_message, acts_as_tool_call, and acts_as_model class macros for Mongoid documents. Include this module (or let the Railtie do it) and call the appropriate macro inside your document class.
Constant Summary collapse
- @@install_lock =
rubocop:disable Style/ClassVars
Mutex.new
Class Method Summary collapse
- .included(base) ⇒ Object
-
.install! ⇒ Object
Hook executed when a class does ‘include Mongoid::Document`.
Class Method Details
.included(base) ⇒ Object
18 19 20 21 |
# File 'lib/ruby_llm/mongoid/acts_as.rb', line 18 def self.included(base) super RubyLLM.config.model_registry_source ||= RubyLLM::Mongoid::MongoidSource.new end |
.install! ⇒ Object
Hook executed when a class does ‘include Mongoid::Document`. Injects our class-method macros onto every Mongoid document automatically so users don’t have to ‘include RubyLLM::Mongoid::ActsAs` explicitly.
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/ruby_llm/mongoid/acts_as.rb', line 28 def self.install! return unless defined?(::Mongoid::Document) @@install_lock.synchronize do return if ::Mongoid::Document.respond_to?(:acts_as_chat) ::Mongoid::Document.module_eval do include RubyLLM::Mongoid::ActsAs end end end |