Sha256: fc6f34a78cb78af67c6fdd49313929bd3ad5792a696b7e60df7eb12f07e0c6fb

Contents?: true

Size: 684 Bytes

Versions: 2

Compression:

Stored size: 684 Bytes

Contents

require 'spyke/relation'
require 'spyke/scope_registry'

module Spyke
  module Scoping
    extend ActiveSupport::Concern

    module ClassMethods
      delegate :where, :build, :any?, :empty?, to: :all
      delegate :using, to: :all

      def all
        current_scope || Relation.new(self, uri: uri)
      end

      def scope(name, code)
        define_singleton_method name, code
      end

      def current_scope=(scope)
        ScopeRegistry.set_value_for(:current_scope, name, scope)
      end

      def current_scope
        ScopeRegistry.value_for(:current_scope, name)
      end
    end

    private

      def scope
        @scope ||= self.class.all
      end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
spyke-2.0.1 lib/spyke/scoping.rb
spyke-2.0.0 lib/spyke/scoping.rb