Module: Cuprum::Collections::Scopes::Composition

Included in:
Base
Defined in:
lib/cuprum/collections/scopes/composition.rb

Overview

Defines a fluent interface for composing scopes.

Instance Method Summary collapse

Instance Method Details

#and(hash = nil, &block) ⇒ Object #and(scope) ⇒ Object Also known as: where

Overloads:

  • #and(hash = nil, &block) ⇒ Object

    Parses the hash or block and combines using a logical AND.

    See Also:

    • Cuprum::Collections::Scopes::Criteria::Parser#parse.
  • #and(scope) ⇒ Object

    Combines with the current scope using a logical AND.

    Returns self if the given scope is empty.



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/cuprum/collections/scopes/composition.rb', line 17

def and(*args, &)
  if scope?(args.first)
    return and_scope(args.first) || and_generic_scope(args.first)
  end

  scope = builder.build(*args, &)

  # We control the current and generated scopes, so we can skip validation
  # and transformation.
  builder.build_conjunction_scope(scopes: [self, scope], safe: false)
end

#not(hash = nil, &block) ⇒ Object #not(scope) ⇒ Object

Overloads:

  • #not(hash = nil, &block) ⇒ Object

    Parses and inverts the hash or block and combines using a logical AND.

    See Also:

    • Cuprum::Collections::Scopes::Criteria::Parser#parse.
  • #not(scope) ⇒ Object

    Inverts and combines with the current scope using a logical AND.

    Returns self if the given scope is empty.



39
40
41
42
43
# File 'lib/cuprum/collections/scopes/composition.rb', line 39

def not(...)
  scope = builder.build(...).invert

  self.and(scope)
end

#and(hash = nil, &block) ⇒ Object #and(scope) ⇒ Object

Overloads:

  • #and(hash = nil, &block) ⇒ Object

    Parses the hash or block and combines using a logical OR.

    See Also:

    • Cuprum::Collections::Scopes::Criteria::Parser#parse.
  • #and(scope) ⇒ Object

    Combines with the current scope using a logical OR.

    Returns self if the given scope is empty.



54
55
56
57
58
59
60
61
62
63
64
# File 'lib/cuprum/collections/scopes/composition.rb', line 54

def or(*args, &)
  if scope?(args.first)
    return or_scope(args.first) || or_generic_scope(args.first)
  end

  scope = builder.build(*args, &)

  # We control the current and generated scopes, so we can skip validation
  # and transformation.
  builder.build_disjunction_scope(scopes: [self, scope], safe: false)
end