Sha256: c4406c4ffd03bc533fd05932b9295a270aa9a01bcdaf641b985627ecfc402120

Contents?: true

Size: 683 Bytes

Versions: 11

Compression:

Stored size: 683 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, 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

11 entries across 11 versions & 1 rubygems

Version Path
spyke-4.1.1 lib/spyke/scoping.rb
spyke-4.1.0 lib/spyke/scoping.rb
spyke-4.0.1 lib/spyke/scoping.rb
spyke-4.0.0 lib/spyke/scoping.rb
spyke-3.1.5 lib/spyke/scoping.rb
spyke-3.1.4 lib/spyke/scoping.rb
spyke-3.1.3 lib/spyke/scoping.rb
spyke-3.1.2 lib/spyke/scoping.rb
spyke-3.1.1 lib/spyke/scoping.rb
spyke-3.1.0 lib/spyke/scoping.rb
spyke-3.0.0 lib/spyke/scoping.rb