Sha256: a4a1dcd762f6b5cb564d0491b933f5d3cf45d7374ac233ec621c14b9138ab112

Contents?: true

Size: 744 Bytes

Versions: 1

Compression:

Stored size: 744 Bytes

Contents

module Superstore
  module Scoping
    extend ActiveSupport::Concern

    included do
      singleton_class.class_eval do
        delegate :find, :find_by_id, :first, :all, to: :scope
        delegate :find_each, :find_in_batches, to: :scope
        delegate :select, :where, :where_ids, to: :scope
      end

      class_attribute :default_scopes, instance_writer: false, instance_predicate: false
      self.default_scopes = []
    end

    module ClassMethods
      def scope
        self.current_scope ||= Scope.new(self)
      end

      def current_scope
        Thread.current["#{self}_current_scope"]
      end

      def current_scope=(new_scope)
        Thread.current["#{self}_current_scope"] = new_scope
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
superstore-2.1.0 lib/superstore/scoping.rb