lib/searchkick/relation.rb in searchkick-5.0.4 vs lib/searchkick/relation.rb in searchkick-5.0.5

- old
+ new

@@ -6,10 +6,13 @@ # and has no impact on query after being executed # TODO freeze body object? delegate :body, :params, to: :query delegate_missing_to :private_execute + attr_reader :model + alias_method :klass, :model + def initialize(model, term = "*", **options) @model = model @term = term @options = options @@ -24,12 +27,11 @@ "#<#{self.class.name} [#{entries.join(', ')}]>" end def execute Searchkick.warn("The execute method is no longer needed") - private_execute - self + load end # experimental def limit(value) clone.limit!(value) @@ -193,14 +195,29 @@ # experimental def except(*keys) Relation.new(@model, @term, **@options.except(*keys)) end + # experimental + def load + private_execute + self + end + def loaded? !@execute.nil? end + def respond_to_missing?(method_name, include_all) + Results.new(nil, nil, nil).respond_to?(method_name, include_all) || super + end + + # TODO uncomment in 6.0 + # def to_yaml + # private_execute.to_a.to_yaml + # end + private def private_execute @execute ||= query.execute end @@ -218,8 +235,13 @@ # provides *very* basic protection from unfiltered parameters # this is not meant to be comprehensive and may be expanded in the future def ensure_permitted(obj) obj.to_h + end + + def initialize_copy(other) + super + @execute = nil end end end