Sha256: 304aa8bcbbc613a015fb3c172690c336e35d1e65bf934b6b3c3055bb8a7b0034

Contents?: true

Size: 699 Bytes

Versions: 21

Compression:

Stored size: 699 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 :with, :with_fallback, 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

21 entries across 21 versions & 1 rubygems

Version Path
spyke-7.2.2 lib/spyke/scoping.rb
spyke-7.1.1 lib/spyke/scoping.rb
spyke-7.1.0 lib/spyke/scoping.rb
spyke-7.0.0 lib/spyke/scoping.rb
spyke-6.1.3 lib/spyke/scoping.rb
spyke-6.1.2 lib/spyke/scoping.rb
spyke-6.1.1 lib/spyke/scoping.rb
spyke-6.1.0 lib/spyke/scoping.rb
spyke-6.0.0 lib/spyke/scoping.rb
spyke-5.4.3 lib/spyke/scoping.rb
spyke-5.4.2 lib/spyke/scoping.rb
spyke-5.4.1 lib/spyke/scoping.rb
spyke-5.4.0 lib/spyke/scoping.rb
spyke-5.3.4 lib/spyke/scoping.rb
spyke-5.3.3 lib/spyke/scoping.rb
spyke-5.3.2 lib/spyke/scoping.rb
spyke-5.3.1 lib/spyke/scoping.rb
spyke-5.3.0 lib/spyke/scoping.rb
spyke-5.2.0 lib/spyke/scoping.rb
spyke-5.1.0 lib/spyke/scoping.rb