Module: ParadeDB::Model
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/parade_db/model.rb
Defined Under Namespace
Modules: ClassMethods
Constant Summary collapse
- INJECTED_CLASS_METHODS =
[ :paradedb_search, :more_like_this, :with_facets, :facets, :with_agg, :facets_agg, :aggregate_by, :paradedb_arel, :paradedb_index, :paradedb_index_class, :paradedb_index_classes, :paradedb_indexed_fields, :paradedb_key_field, :paradedb_index_name, :paradedb_validate_index! ].freeze
Class Method Summary collapse
Class Method Details
.detect_method_collision!(base, method_name) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/parade_db/model.rb', line 46 def self.detect_method_collision!(base, method_name) return unless base.singleton_methods(false).include?(method_name) method = base.method(method_name) source_location = method.source_location ? method.source_location.join(":") : "unknown" raise ParadeDB::MethodCollisionError, "Method collision on #{base.name}.#{method_name}. " \ "Existing method owner=#{method.owner}, source=#{source_location}. " \ "Rename the existing method or remove it before including ParadeDB::Model." end |
.included(base) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/parade_db/model.rb', line 28 def self.included(base) unless defined?(ActiveRecord::Base) && base == ActiveRecord::Base INJECTED_CLASS_METHODS.each do |method_name| detect_method_collision!(base, method_name) end end base.extend(ClassMethods) # Provide `.search` as a convenience alias unless the model already defines it. # In collision scenarios (Searchkick, Ransack, etc.), users can call `.paradedb_search`. unless base.respond_to?(:search) base.singleton_class.define_method(:search) do |column| paradedb_search(column) end end end |