Sha256: f685d63ce9e165bf834dc5b8a4f17b9adf0dc99cf80d4b1c81902bd895cd1712

Contents?: true

Size: 611 Bytes

Versions: 7

Compression:

Stored size: 611 Bytes

Contents

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

module Spyke
  module Scopes
    extend ActiveSupport::Concern

    module ClassMethods
      delegate :all, :where, to: :current_scope

      def scope(name, code)
        self.class.send :define_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) || Relation.new(self, uri: uri)
      end
    end

    private

      def current_scope
        self.class.current_scope
      end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
spyke-1.2.0 lib/spyke/scopes.rb
spyke-1.1.2 lib/spyke/scopes.rb
spyke-1.1.1 lib/spyke/scopes.rb
spyke-1.1.0 lib/spyke/scopes.rb
spyke-1.0.2 lib/spyke/scopes.rb
spyke-1.0.1 lib/spyke/scopes.rb
spyke-1.0.0 lib/spyke/scopes.rb