Module: Lupa::ScopeMethods Private

Defined in:
lib/lupa/scope_methods.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Note:

This module is included automatically by Lupa and should not be included manually in your code.

Internal module that provides common functionality to Scope classes. This module is automatically included in the Scope class defined within your search class.

It provides access to two key attributes:

  • ‘scope`: The current scope being searched

  • ‘search_attributes`: The hash of search parameters

Examples:

Accessing scope and search_attributes in a Scope class

class ProductSearch < Lupa::Search
  class Scope
    # scope and search_attributes are available here
    def name
      # scope is the current ActiveRecord relation (or any chainable object)
      scope.where('name LIKE ?', "%#{search_attributes[:name]}%")
    end

    def price_range
      # search_attributes contains all search parameters
      if search_attributes[:price_range]
        scope.where(price: search_attributes[:price_range])
      else
        scope
      end
    end
  end
end

Since:

  • 0.1.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#scopeObject

The current scope object that search methods will operate on. This is typically an ActiveRecord::Relation or similar chainable object. The scope is updated after each search method is called.

Examples:

Accessing the scope in a search method

def category
  # scope is the current state of the query chain
  scope.where(category_id: search_attributes[:category])
end

Returns:

  • (Object)

    the current scope object



48
49
50
# File 'lib/lupa/scope_methods.rb', line 48

def scope
  @scope
end

#search_attributesObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 0.1.0



68
69
70
# File 'lib/lupa/scope_methods.rb', line 68

def search_attributes
  @search_attributes
end

Instance Method Details

#initialize(scope, search_attributes) ⇒ ScopeMethods

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Initializes a new Scope instance with the given scope and search attributes. This method is called automatically by Lupa::Search and should not be called directly.

Examples:

Internal usage (automatically called by Lupa)

# This happens internally when you call:
ProductSearch.new(Product.all).search(name: 'chair')
# Lupa automatically calls:
ProductSearch::Scope.new(Product.all, { name: 'chair' })

Parameters:

  • scope (Object)

    the initial scope object to search on (e.g., ActiveRecord::Relation)

  • search_attributes (Hash)

    the hash of search parameters with symbolized keys

Returns:

Since:

  • 0.1.0



85
86
87
88
# File 'lib/lupa/scope_methods.rb', line 85

def initialize(scope, search_attributes)
  @scope             = scope
  @search_attributes = search_attributes
end