Module: DataMapper::Model::Scope

Included in:
DataMapper::Model
Defined in:
lib/dm-core/model/scope.rb

Overview

Module with query scoping functionality.

Scopes are implemented using simple array based stack that is thread local. Default scope can be set on a per repository basis.

Scopes are merged as new queries are nested. It is also possible to get exclusive scope access using with_exclusive_scope

Instance Method Summary collapse

Instance Method Details

#current_scopeObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

TODO: document



34
35
36
# File 'lib/dm-core/model/scope.rb', line 34

def current_scope
  scope_stack.last || default_scope(repository.name)
end

#default_scope(repository_name = default_repository_name) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

TODO: document



15
16
17
18
19
20
21
22
23
# File 'lib/dm-core/model/scope.rb', line 15

def default_scope(repository_name = default_repository_name)
  @default_scope ||= {}

  @default_scope[repository_name] ||= if repository_name == default_repository_name
    {}
  else
    default_scope(default_repository_name).dup
  end
end

#queryObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns query on top of scope stack



28
29
30
# File 'lib/dm-core/model/scope.rb', line 28

def query
  Query.new(repository, self, current_scope).freeze
end