-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement Scopes::Composition::Disjunction.
- Loading branch information
1 parent
f5d37bb
commit 2a5059f
Showing
8 changed files
with
223 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'cuprum/collections/scopes/composition' | ||
|
||
module Cuprum::Collections::Scopes::Composition | ||
# Defines composition behavior for disjunction scopes. | ||
module Disjunction | ||
# (see Cuprum::Collections::Scopes::Composition#or) | ||
def or(*args, &block) | ||
scopes = | ||
if args.first.is_a?(Cuprum::Collections::Scopes::Base) && | ||
args.first.type == :disjunction | ||
args.first.scopes.map do |scope| | ||
builder.transform_scope(scope: scope) | ||
end | ||
else | ||
[builder.build(*args, &block)] | ||
end | ||
|
||
with_scopes([*self.scopes, *scopes]) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
spec/cuprum/collections/scopes/composition/disjunction_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'cuprum/collections/rspec/contracts/scopes/composition_contracts' | ||
require 'cuprum/collections/scopes/base' | ||
require 'cuprum/collections/scopes/composition/disjunction' | ||
require 'cuprum/collections/scopes/container' | ||
require 'cuprum/collections/scopes/criteria_scope' | ||
|
||
RSpec.describe Cuprum::Collections::Scopes::Composition::Disjunction do | ||
include Cuprum::Collections::RSpec::Contracts::Scopes::CompositionContracts | ||
|
||
subject(:scope) { described_class.new(scopes: scopes) } | ||
|
||
let(:described_class) { Spec::ExampleScope } | ||
let(:scopes) { [] } | ||
|
||
example_class 'Spec::ExampleScope', Cuprum::Collections::Scopes::Base \ | ||
do |klass| | ||
klass.include Cuprum::Collections::Scopes::Container | ||
klass.include Cuprum::Collections::Scopes::Composition::Disjunction # rubocop:disable RSpec/DescribedClass | ||
|
||
klass.define_method(:type) { :disjunction } | ||
end | ||
|
||
def build_scope(filters = nil, &block) | ||
scope_class = Cuprum::Collections::Basic::Scopes::CriteriaScope | ||
|
||
if block_given? | ||
scope_class.build(&block) | ||
else | ||
scope_class.build(filters) | ||
end | ||
end | ||
|
||
include_contract 'should compose scopes for disjunction' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters