Module: Cuprum::Collections::Relations::Scope

Included in:
Collection, Cuprum::Collections::Resource
Defined in:
lib/cuprum/collections/relations/scope.rb

Overview

Methods for defining a scope for a relation.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#scopeCuprum::Collections::Scopes::Base

Returns the configured scope for the relation.

Returns:



19
20
21
# File 'lib/cuprum/collections/relations/scope.rb', line 19

def scope
  @scope
end

Instance Method Details

#initialize(scope: nil, **) ⇒ Object

Parameters:



11
12
13
14
15
# File 'lib/cuprum/collections/relations/scope.rb', line 11

def initialize(scope: nil, **parameters)
  super(**parameters)

  @scope = apply_scope(default_scope, scope)
end

#with_scope(scope) ⇒ Cuprum::Collections::Relations::Scope #with_scope {|query| ... } ⇒ Cuprum::Collections::Relations::Scope

Overloads:



41
42
43
# File 'lib/cuprum/collections/relations/scope.rb', line 41

def with_scope(value = nil, &block)
  dup.tap { |copy| copy.scope = apply_scope(scope, value || block) }
end