Module: Cuprum::Collections::Scopes::Building
- Included in:
- Basic::Scopes::Builder, Builder
- Defined in:
- lib/cuprum/collections/scopes/building.rb
Overview
Abstraction for generating scopes for a given collection.
Defined Under Namespace
Modules: ClassMethods Classes: AbstractBuilderError, UnknownScopeTypeError
Instance Method Summary collapse
- #build(*args) ⇒ Object
-
#build_all_scope ⇒ Object
Creates a new all scope.
-
#build_conjunction_scope(scopes:, safe: true) ⇒ Object
Creates a new logical AND scope wrapping the given scopes.
-
#build_criteria_scope(criteria:, inverted: false, safe: true) ⇒ Object
Creates a new scope wrapping the given criteria.
-
#build_disjunction_scope(scopes:, safe: true) ⇒ Object
Creates a new logical OR scope wrapping the given scopes.
-
#build_none_scope ⇒ Object
Creates a new none scope.
-
#transform_scope(scope:) ⇒ Object
Creates a new scope with the same scope type and properties.
Instance Method Details
#build(hash = nil, &block) ⇒ Object #build(scope) ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/cuprum/collections/scopes/building.rb', line 41 def build(*args, &) if args.first.is_a?(Cuprum::Collections::Scopes::Base) return transform_scope(scope: args.first) end criteria_scope_class.build(*args, &) end |
#build_all_scope ⇒ Object
Creates a new all scope.
50 51 52 |
# File 'lib/cuprum/collections/scopes/building.rb', line 50 def build_all_scope all_scope_class.new end |
#build_conjunction_scope(scopes:, safe: true) ⇒ Object
Creates a new logical AND scope wrapping the given scopes.
60 61 62 63 64 65 66 67 68 |
# File 'lib/cuprum/collections/scopes/building.rb', line 60 def build_conjunction_scope(scopes:, safe: true) if safe validate_scopes!(scopes) scopes = transform_scopes(scopes) end conjunction_scope_class.new(scopes:) end |
#build_criteria_scope(criteria:, inverted: false, safe: true) ⇒ Object
Creates a new scope wrapping the given criteria.
75 76 77 78 79 |
# File 'lib/cuprum/collections/scopes/building.rb', line 75 def build_criteria_scope(criteria:, inverted: false, safe: true) validate_criteria!(criteria) if safe criteria_scope_class.new(criteria:, inverted:) end |
#build_disjunction_scope(scopes:, safe: true) ⇒ Object
Creates a new logical OR scope wrapping the given scopes.
87 88 89 90 91 92 93 94 95 |
# File 'lib/cuprum/collections/scopes/building.rb', line 87 def build_disjunction_scope(scopes:, safe: true) if safe validate_scopes!(scopes) scopes = transform_scopes(scopes) end disjunction_scope_class.new(scopes:) end |
#build_none_scope ⇒ Object
Creates a new none scope.
98 99 100 |
# File 'lib/cuprum/collections/scopes/building.rb', line 98 def build_none_scope none_scope_class.new end |
#transform_scope(scope:) ⇒ Object
Creates a new scope with the same scope type and properties.
103 104 105 106 107 |
# File 'lib/cuprum/collections/scopes/building.rb', line 103 def transform_scope(scope:) validate_scope!(scope) build_transformed_scope(scope) end |